assertion problem in Mixed mode DLL

C

Craig Klementowski

Pardon the cross post, but I'm not sure where exactly to post this question.

We have MFC application using many MFC extention DLL's. We started using a
new MFC extention DLL that is mixed mode so we could use some .Net
components we have built.

We are getting an assertion in ~CCmdTarget when exiting our app when after
making a call to Windows Forms MessageBox. On line 48, m_dwRef is 2 for some
reason.

Offending line - System::Windows::Forms::MessageBox::Show("Test");

Is there some function I need to call to release something that I am
missing? Any ideas?

Thanks...

Craig Klementowski


CCmdTarget::~CCmdTarget()
{
#ifndef _AFX_NO_OLE_SUPPORT
if (m_xDispatch.m_vtbl != 0)
((COleDispatchImpl*)&m_xDispatch)->Disconnect();

#endif
#ifdef _AFXDLL
m_pModuleState = NULL;
#endif
}

Call Stack:
mfc71d.dll!CCmdTarget::~CCmdTarget() Line 48 + 0x19 C++
mfc71d.dll!COleMessageFilter::~COleMessageFilter() Line 59 + 0xf C++
mfc71d.dll!COleMessageFilter::`scalar deleting destructor'() + 0xf C++
mfc71d.dll!AfxOleTerm(int bJustRevoke=0) Line 114 + 0x22 C++
mfc71d.dll!AfxOleTermOrFreeLib(int bTerm=1, int bJustRevoke=0) Line 139
C++
mfc71d.dll!AfxWinTerm() Line 48 C++
mfc71d.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ *
hPrevInstance=0x00000000, char * lpCmdLine=0x0024237f, int nCmdShow=5) Line
64 C++
MyApp.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ *
hPrevInstance=0x00000000, char * lpCmdLine=0x0024237f, int nCmdShow=5) Line
25 C++
MyApp.exe!WinMainCRTStartup() Line 390 + 0x39 C
kernel32.dll!77e814c7()
 
F

Ferdinand Oeinck

I Craig,

what a coincidence! I installed last weekend Windows Server 2003 and Visual
Studio 7.1 on my new dual xeon dell system and after I copied my project
directory and compiled my most important app, I got exaclty the same failed
assertion as you do.

I cured it by carefully removing all unnessesarry calls to CoInitializeEx
and CoUninitialize. Now there is only one call to AfxOleInit() and the
assertion failure went away. A strange thing is that my app worked great in
DEBUG mode on w2k without any assertion failure. So Microsoft has changed
something in OLE....

But there is another point of concern about your code. As from what you
describe, you can become a victim of the .Net loaderlock issue very easily.
You do not tell us if you load the CLR with CorBindToRuntimeEx in your MFC
app. I you do not, then you could have a big change to run into the loader
lock issue!

Search for 'loader lock issue' on Google....

Ferdinand.
 
C

Craig Klementowski

We carefully read what the MSDN said and did that so we should be safe from
the loader lock issue.

I'll try and cleanup the CoInitializeEx, CoUninitialize, and AfxOleInit
calls.

Thanks,

Craig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top