B
Ben Terry
I have imported a legacy C++ project into a VisualStudio.NET 2003 solution.
I have some new C# projects in the solution as well. I am using the managed
extensions in my C++ project so that I can use the managed C# objects within
my C++ project. Here's the problem: I am getting a debug assertion in
cmdtarg.cpp (line 48) of my main CWinApp derived class when I exit the
application:
CCmdTarget::~CCmdTarget()
{
....
ASSERT(m_dwRef <= 1); // <<<< Line 48 where I am getting the assertion.
....
}
The strange thing is that I only get this assertion if I have created a
managed gcroot<> object within the main CWinApp derived class. Why does
creating a managed object increase the ref count on CWinApp? That seems
very odd. Here is how I am creating the managed object within CWinApp:
In the header:
#using <mscorlib.dll>
#using <system.dll>
#using <system.windows.forms.dll>
#using "PetToolTCPLib.dll" // Library of my C# managed classes
using namespace PetToolTCPLib;
using namespace System;
In the .cpp:
#pragma push_macro("new")
#undef new
m_pTCPTool = new CToolMain();
#pragma pop_macro("new")
m_pTCPTool->Show();
In the destructor of the .cpp:
m_pTCPTool->Close();
m_pTCPTool->Dispose();
m_pTCPTool = NULL;
Once again, my question is: Why does creating a managed object increase the
ref count on CWinApp?
How do I resolve this problem?
Ben
I have some new C# projects in the solution as well. I am using the managed
extensions in my C++ project so that I can use the managed C# objects within
my C++ project. Here's the problem: I am getting a debug assertion in
cmdtarg.cpp (line 48) of my main CWinApp derived class when I exit the
application:
CCmdTarget::~CCmdTarget()
{
....
ASSERT(m_dwRef <= 1); // <<<< Line 48 where I am getting the assertion.
....
}
The strange thing is that I only get this assertion if I have created a
managed gcroot<> object within the main CWinApp derived class. Why does
creating a managed object increase the ref count on CWinApp? That seems
very odd. Here is how I am creating the managed object within CWinApp:
In the header:
#using <mscorlib.dll>
#using <system.dll>
#using <system.windows.forms.dll>
#using "PetToolTCPLib.dll" // Library of my C# managed classes
using namespace PetToolTCPLib;
using namespace System;
In the .cpp:
#pragma push_macro("new")
#undef new
m_pTCPTool = new CToolMain();
#pragma pop_macro("new")
m_pTCPTool->Show();
In the destructor of the .cpp:
m_pTCPTool->Close();
m_pTCPTool->Dispose();
m_pTCPTool = NULL;
Once again, my question is: Why does creating a managed object increase the
ref count on CWinApp?
How do I resolve this problem?
Ben