D
Drew
I have recently converted all of my native C++ dll's to be compiled
with the /CLR switch. After doing this, I notcied a very strange and
frustrating issue.
One of my managed dll's calls another using a COM smartptr
(MSXML2::IXMLDOMDocumentPtr to be exact). When calling my function in
another managed DLL, my app starts throwing exceptions.
If I step into my function, before getting into my function, I see a
call to AddRef() and later a call to Release() on my smartptr. When I
am in the Release() call I see several levels of calls into the CLR
(mscorwks.dll). After this, the IP gets lost somewhere.
Now, if I step over my function, it comes back ok, but the smartptr is
messed up and when I try to use it, an exception is thrown.
The strange thing is, if I add the function that is in my separate
dll, into the same dll that is making the call, everything works fine.
I've tried reproducing this in a small test case, but it appears to
work. I don't know if I'm doing something wrong and it manages to work
by accident in the small test case or not. What is going on with the
COM object (I've even tried using a dump ptr- same problem)
I have gone over the "Converting Managed Extensions ... from Pure ...
to Mixed Mode". All my settings are set according to the document.
Here's a snippet of my code.
CDEGlobalEngine::TestFn()
{
MSXML2::IXMLDOMDocumentPtr pXmlDoc;
HRESULT hr = pXmlDoc.CreateInstance(CLSID_DOMDocument);
if (SUCCEEDED(hr))
{
// if i change my function to not pass in the pXmlDoc, everything
works fine
boolbReturnCode = CXTXml::LoadXml("options.xml", pXmlDoc);
}
}
Here's my code to init the CRT :
CDEGlobalEngine::CDEGlobalEngine()
{
HMODULE hDll = ::GetModuleHandle("otherDLL.dll");
if (hDll)
{
pfnEnsureInit pfnDll = (pfnEnsureInit) ::GetProcAddress(hDll,
"_DllEnsureInit@0");
if (pfnDll)
{
pfnDll();
}
}
// init COM for MSXML library
CoInitialize(NULL);
}
with the /CLR switch. After doing this, I notcied a very strange and
frustrating issue.
One of my managed dll's calls another using a COM smartptr
(MSXML2::IXMLDOMDocumentPtr to be exact). When calling my function in
another managed DLL, my app starts throwing exceptions.
If I step into my function, before getting into my function, I see a
call to AddRef() and later a call to Release() on my smartptr. When I
am in the Release() call I see several levels of calls into the CLR
(mscorwks.dll). After this, the IP gets lost somewhere.
Now, if I step over my function, it comes back ok, but the smartptr is
messed up and when I try to use it, an exception is thrown.
The strange thing is, if I add the function that is in my separate
dll, into the same dll that is making the call, everything works fine.
I've tried reproducing this in a small test case, but it appears to
work. I don't know if I'm doing something wrong and it manages to work
by accident in the small test case or not. What is going on with the
COM object (I've even tried using a dump ptr- same problem)
I have gone over the "Converting Managed Extensions ... from Pure ...
to Mixed Mode". All my settings are set according to the document.
Here's a snippet of my code.
CDEGlobalEngine::TestFn()
{
MSXML2::IXMLDOMDocumentPtr pXmlDoc;
HRESULT hr = pXmlDoc.CreateInstance(CLSID_DOMDocument);
if (SUCCEEDED(hr))
{
// if i change my function to not pass in the pXmlDoc, everything
works fine
boolbReturnCode = CXTXml::LoadXml("options.xml", pXmlDoc);
}
}
Here's my code to init the CRT :
CDEGlobalEngine::CDEGlobalEngine()
{
HMODULE hDll = ::GetModuleHandle("otherDLL.dll");
if (hDll)
{
pfnEnsureInit pfnDll = (pfnEnsureInit) ::GetProcAddress(hDll,
"_DllEnsureInit@0");
if (pfnDll)
{
pfnDll();
}
}
// init COM for MSXML library
CoInitialize(NULL);
}