views:

656

answers:

3

Question: I have a .NET dll which I use from a C++ program. Now I have to register the dll programmatically on a deployment computer.


How do i do that (programmatically! not using regasm) ? I remember, when I once called a VB6 dll from a C++ dll, I had to use DllRegisterServer and DllUnregisterServer.

Is that still so with a .NET dll ?
It seems I have to somehow add the dllregisterserver function to the .NET dll...

A: 
HMODULE hModule = ::LoadLibrary(strDllName);
CTLREGPROC DLLRegisterServer = (CTLREGPROC)::GetProcAddress(hModule,"DllRegisterServer" );
DLLRegisterServer();
::FreeLibrary(hModule) ;

Go to this link to view more

Ballin
The point is GetProcAddress(hModule,"DllRegisterServer" ); returns NULL because there's no function DllRegisterServer in the dll...
Quandary
+1  A: 

Can you use process monitor to see what system changes (basically registry changes I think) are made when you use regasm.exe to register your dll, and then make those changes programatically instead?

Sam Holder
Yes, that's the way to go with pure C/C++. Nice, but I think it might take time to figure out how to get the data to write there...
Quandary
+4  A: 

YUK, .NET dlls don't have DllRegisterServer, so you have to write a .NET installer, executing this somewhere:

Assembly asm = Assembly.LoadFile (@"c:\temp\ImageConverter.dll");
RegistrationServices regAsm = new RegistrationServices();
bool bResult = regAsm.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase);
Quandary
+1, this is the correct answer.
Hans Passant