1

I would like to know which is the member (if any) in the .NET Framework class library to replace a external (process) call to RegSvr32.exe and Regasm.exe to avoid doing those process calls and stderror/stdoutput/exit-code handling.

I've found the method: System.Runtime.InteropServices.RegistrationServices.RegisterAssembly, which in its description says:

Registers the classes in a managed assembly to enable creation from COM

...So it says is for managed assemblies and it takes an Assembly type as argument (which only can load/handle managed assemblies), then for sure that method must be the equivalent for calling Regasm.exe to register .NET assemblies. Now, which is the equivalent member/class/method or the platform invoke definitions for calling RegSvr32.exe to register a native dll?.

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • If you take a look at the referencesource (http://referencesource.microsoft.com/#mscorlib/system/runtime/interopservices/registrationservices.cs,570dfb2ebf3a1960) you'll see that regsvr32/regasm arent called (via p/invoke or otherwise) but rather it appears their functionality is duplicated directly by creating all the necessary registry keys. I doubt youll find anything short of p/invoke for dealing with unmanaged assemblies. I could be wrong though, haven't looked into it except for the source linked above but if there was I'd think they'd use it rather that creating the keys the way they do – pinkfloydx33 Sep 09 '17 at 08:47
  • 2
    regsvr32 is not comparable to regasm. regsvr32 just calls the DllRegisterServer/DllUnregisterServer exported functions of a native DLL. You can find a .NET equivalent here for example: https://www.zorched.net/2009/01/01/register-and-unregister-com-dll-from-net-code/ – Simon Mourier Sep 09 '17 at 08:52
  • 1
    @Simon Mourier Im not comparing them, I just asked for a solution for both cases (register managed dlls, and register native dlls). I would like to register native dlls (which I didn't developed) from my managed code. Thankyou for sharing that resource, but could you clarify whether the export name for this kind of operation always is 'DllRegisterServer' and cannot be any other name?, because in that article it says "The only thing we need to do is figure out what functions to call."like saying the export name can vary depending on the developer's decission,that is not clear at all for me.thx. – ElektroStudios Sep 09 '17 at 09:16
  • 2
    They are really two very different questions. Regasm is meant for .NET COM types (I've written an equivalent here: https://stackoverflow.com/questions/35782404/registering-a-com-without-admin-rights) and Regsvr32 is for COM types in non .NET DLLs. The export is always DllRegisterServer: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682162.aspx – Simon Mourier Sep 09 '17 at 09:21
  • AFAIK, RegSvr32 also has code to account for bitness conflicts (calling the 64-bit regsvr32 on a 32-bit DLL results in it spawning the 32-bit regsvr32 to do the work). – Medinoc Sep 11 '17 at 11:07
  • 1
    I solved it thanks to the url linked by @Simon Mourier using DllRegisterServer. Thanks everyone for commenting and trying to help. I did an universal method but since this question is duplicated I cannot publish my own answer... I don't understand this S.O policy, if its my question, even when it is considered a duplicated I should be able to answer my question to share a solution for the rest of the world. Well, I'm talking too much. – ElektroStudios Sep 11 '17 at 12:07
  • You can vote to reopen the question or flag the question if you need any help regarding to the question status. – Reza Aghaei Feb 24 '18 at 08:43

0 Answers0