CComPtr 销毁期间出现异常
我有一个声明为
CComPtr<IXMLDOMDocument2> m_spXMLDoc;
XML 文档的成员变量是这样创建的
CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument2, (void**)&m_spXMLDoc));
现在当应用程序退出时,会抛出异常。 Callstack 指向 p->Release()
~CComPtrBase() throw()
{
if (p)
p->Release();
}
当我将鼠标悬停在 VS 调试器中的 p
时,它指向一些有效的内存。
最后一个调用堆栈指向 msxm6 中的异常
msxml6.dll!3d6cXX03()
有什么建议,可能是什么原因?我不认为这是一个 CComPtr
问题。
I have a member variable declared as
CComPtr<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了类似的问题,最终我发现这只是一个错误。我必须确保在破坏
CComPtr
之后调用CoUninitialize()
。否则,就会出现异常。在与
CoUninitialize()
调用相同的函数中声明CComPt
r 将导致异常,因为销毁发生在函数终止后。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 theCComPtr
is destructed. Otherwise, there will be an exception.Declaring
CComPt
r in the same function as theCoUninitialize()
call will cause the exception since the destruction occurs after the function terminates.在程序退出之前执行此操作:
我之前就见过这种情况。这个问题与引用计数有关(显然),但我从来没有想过寻找原因。希望这有帮助!
Do this before your program exits:
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!
您应该使用 CComPtr 的成员函数创建实例:
You should create the instance using the member functions of CComPtr:
我正在研究一个类似的问题,其中 IExplorer 从客户端下抓取当前网页的 com 服务器。
结果似乎无法执行发布,而是出现诸如服务器已断开客户端连接之类的 com 错误。
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.