473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

assertion problem in Mixed mode DLL

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()
Nov 16 '05 #1
2 5392
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.
"Craig Klementowski" <no**************@nospam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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()


Nov 16 '05 #2

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

"Ferdinand Oeinck" <ferdo@NO****@home.nl> wrote in message
news:bn**********@news1.tilbu1.nb.home.nl...
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.
"Craig Klementowski" <no**************@nospam.hotmail.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
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()


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike Kamzyuk | last post by:
Hello all. Basically, I need to call a mixed-mode dll's function (which uses managed code) from a native or mixed-mode dll function (which does not use managed code). I'm wondering if this could...
0
by: Edward Diener | last post by:
I have some questions about the instructions for creating a mixed mode DLL in the MSDN topic "Converting Managed Extensions for C++ Projects from Pure Intermediate Language to Mixed Mode" in the...
9
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and...
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
8
by: Nadav | last post by:
Hi, I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid...
3
by: Ben Schwehn | last post by:
Hello I have a mixed mode c++ dll that i want to use from a c# project. However, I get an debug assertion when the dll is loaded. The assertion is in line 1301 in dbgheap.c in the function ...
2
by: Doug Belkofer | last post by:
We have created a fairly complex mixed-mode DLL that we want to use from VB.NET. The mixed-mode DLL is written in C++, and does use the standard C runtime libraries. An unusual thing is happening...
8
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
0
by: emu | last post by:
Hi All, I have an unmanaged C++ application that references a mixed mode image DLL (mixed managed and unmanaged). Under .NET 1.1 we could trust the dll (the mixed mode dll) by running the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.