在特定的调用次数后,CoGetObject()返回E_UNEXPECTED [英] CoGetObject() returns E_UNEXPECTED after a specific count of calls

查看:93
本文介绍了在特定的调用次数后,CoGetObject()返回E_UNEXPECTED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿有人,

我在客户端获得了一个COM服务器和以下代码:

I got a COM Server and the following code on client side:




ITheObjectPtr spITheObjectPtr; ITheObjectsTablePtr spITheObjectsTable; HRESULT hr = CoGetObject(OLESTR("clsid:...-...-...-...-...:"),NULL,__uuidof(ITheObjectsTable),(void**)&spITheObjectsTable); if(FAILED(hr)) { AfxMessageBox("Failed to get object table"); SetDlgItemText(IDC_EDIT_ID, "Failed to get table"); return; } for (int i=0; i<100000; i++) { hr = CoGetObject(OLESTR("clsid:...-...-...-...-...:!Object"),NULL,__uuidof(ITheObject),(void**)&spITheObjectPtr); if (SUCCEEDED(hr)) spITheObjectsTable->RemoveObject(OLESTR("Object")); else if(FAILED(hr)) { AfxMessageBox("Failed to get object"); SetDlgItemText(IDC_EDIT_ID, "Failed to get object"); return; }

TRACE("%d \ n",i);
}

TRACE("%d\n",i); }




RemoveObject()在服务器端看起来像这样:

RemoveObject() is on the server side and looks like this:

STDMETHODIMP CComServer::RemoveObject(BSTR bstrObjectName) { _mapObjects::iterator it_find = mapObjects.find(bstrObjectName); if(it_find != mapObjects.end()) { IUnknown *pIUnkwn = it_find->second; mapObjects.erase(it_find); pIUnkwn->Release(); return S_OK; }

其他

{

返回S_FALSE;

return S_FALSE;

}
}

此代码适用于大约~7,000次重复。

This code works well until about ~7000 repeats.

此时用户句柄的数量(在Process Explorer中看到)快速上升到~10000然后程序失败。

At this points the count of user handles (seen in Process Explorer) starts to rise up to ~10000 quickly and then the program fails.

调用AfxMessageBox("Failed to get object"),但是消息框没有show。

The AfxMessageBox("Failed to get object") is called, but the message box does not show.

CoGetObject()以E_UNEXPECTED返回。

The CoGetObject() returns with E_UNEXPECTED.




任何人都可以向我解释,为什么直到最后它才能运作?我没有以正确的方式发布对象吗?

Can anyone explain to me, why this does not work until the end? Am I not releasing the object the right way?




我正在使用Visual Studio 2008和Windows进行测试7。

I am testing this with Visual Studio 2008 and Windows 7.




招呼,

被杀

推荐答案

ITheObjectPtr 是什么?您确定存储在
spITheObjectPtr 中的旧对象是否已释放,即没有发生内存泄漏?

What ITheObjectPtr is? Are you sure that the old objects stored into spITheObjectPtr are release, i.e. no memory leaks occur?


这篇关于在特定的调用次数后,CoGetObject()返回E_UNEXPECTED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆