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();
>>>>>>>>>ASSERT(m_dwRef <= 1);
#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()
Ferdinand Oeinck - 27 Oct 2003 19:34 GMT
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.
> Pardon the cross post, but I'm not sure where exactly to post this question.
>
[quoted text clipped - 46 lines]
> MyApp.exe!WinMainCRTStartup() Line 390 + 0x39 C
> kernel32.dll!77e814c7()
Craig Klementowski - 29 Oct 2003 16:38 GMT
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
> I Craig,
>
[quoted text clipped - 73 lines]
> > MyApp.exe!WinMainCRTStartup() Line 390 + 0x39 C
> > kernel32.dll!77e814c7()