I have a member variable declared as
CComPtr&开发者_JS百科lt;IXMLDOMDocument2> m_spXMLDoc;
XML document is created like this
CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument2, (void**)&m_spXMLDoc));
Now when application exits, an exception is thrown. Callstack is pointing to p->Release()
~CComPtrBase() throw()
{
if (p)
p->Release();
}
When I hover over to p
in VS debugger, it points to some valid memory.
The last callstack points to exception in msxm6
msxml6.dll!3d6cXX03()
Any suggestions, what could be the reason? I don't think it's a CComPtr
issue.
I had a similar issue and eventually I found that it is was just a bug. I have to make sure that CoUninitialize()
is called AFTER the CComPtr
is destructed. Otherwise, there will be an exception.
int _tmain(int argc, _TCHAR* argv[]) {
CoInitialize(NULL);
mymain();
//put all logic in a separate function so that CComPtr
//is destructed before CoUninitialize()
CoUninitialize();
return 0;
}
Declaring CComPt
r in the same function as the CoUninitialize()
call will cause the exception since the destruction occurs after the function terminates.
Do this before your program exits:
if( m_spXMLDoc.p )
m_spXMLDoc.Release();
I've seen this before myself. The issue is related with reference counting (obviously), but I've never cared to look for the reason. Hope this helps!
You should create the instance using the member functions of CComPtr:
m_spXMLDoc.CoCreateInstance(...)
I'm looking at a similar issue where IExplorer rips the com server for the current web page from under the clients.
The result seems to be that release can't be performed, instead you get com errors like server has disconnected clients.
精彩评论