I've recently been busy working on an ActiveX DLL written in C++/CLI, I chose C++/CLI (instead of C#) because we have "legacy" code in native C++ DLLs, some of which contain MFC exported classes (i.e. MFC Extension DLLs). As such there would have been a horrible amount of "glue" code to get this working in C# so the C++/CLI was the best choice for this sort of project.
Everything seems to have been going very well, until I noticed regasm hanging up on Vista during interop registration, the debug version of the DLL doesn't exhibit the problem, only the release version.
So I fired up WinDbg and setup the Windows symbol server path and launched regasm through the debugger. The stack trace revealed an invalid pointer usage inside AfxTermExtensionModule inside MFC42U. After some research I learned the way that MFC extension DLLs work internally (via CDynLinkLibrary), and some further digging produced this:-
http://support.microsoft.com/kb/154126
My next point of call was the DllMain entry points for the 4 MFC extension DLLs I'm making use of, which revealed that the CDynLinkLibrary instantiation was being carried out inside DllMain()'s DLL_PROCESS_ATTACH switch branch. Following the advice from the Microsoft link above, it becomes obvious that we do indeed need to create a separate exported function for the CDynLinkLibrary instantiation, this way we can call it and wire into the link library chain of our own DLL.
Severe headache, but at least I found a solution!
1 comment:
Sign up for free and get a quote or consult our experts for details. Once we create a brief list of your requirements, we start building your app and deliver it you within days.
Post a Comment