Hello Everyone,
I have the following issue I would like to share with you:
I added to a dynamic library with MFC feature, the /clr option.
Since I have added this option, the library seems to behave properly expect that I cannot set code into DllMain statment as I was doing before the modification.
Let's add a MessageBox after CoInitialize:
#pragma unmanaged
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
g_hThisDll = hInstance;
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
CoInitialize(NULL);
::MessageBox(NULL, "DllMain", "mpOLEAutomationCLR", MB_OK);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
delete g_pcfOleAutomationCLR;
CoUninitialize();
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Now, if I run:
C:\Windows\SysWOW64\regsvr32.exe ".\Debug\mpOLEAutomationCLR.dll"
It prompts the following error dialog box:
Errorregistration message.
If I remove the MessageBox line:
#pragma unmanaged
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
g_hThisDll = hInstance;
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
CoInitialize(NULL);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
delete g_pcfOleAutomationCLR;
CoUninitialize();
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
The regsv32.exe command line will return the expected messagebox.
Expected registration message.
I have added the sample program project to show you or try the issue.
Sample program link
Does somebody have a explanation or a fix to allow me to add code into the DllMain entry point.
Thank you very much in advance.
Happy end year season.
Best regards.
SuperMiqi