我正在客户站点上调试间歇性问题。我已经明白了,对 COM 对象的 Release()
调用似乎没有返回。
第一个日志正在打印,但我从未看到第二个日志。我只能假设对 Release()
的调用由于某种原因从未返回(或者可能是 CoInitializeEx()
)。
我不知道接下来要寻找什么,任何帮助/线索将不胜感激。
Logger::getLogger()->logTrace("AudioCapturer::_shutdown. _pEndpointAudioClient_COM Released. (%s)", _deviceName.c_str());
releaseComObject(_pAudioCaptureClient_COM);
Logger::getLogger()->logTrace("AudioCapturer::_shutdown (%s) succeeded", _deviceName.c_str());
这是支持代码:
IAudioCaptureClient *_pAudioCaptureClient_COM;
// Class that Initializes COM on creation and Unitializes on destruction
AutoCOM::AutoCOM() { CoInitializeEx(NULL, COINIT_MULTITHREADED); }
AutoCOM::~AutoCOM() { CoUninitialize(); }
#define AUTO_COM_SUPPORT AutoCOM _autoCOM
// Safe releasing of COM objects. Zeros the pointer
// to the COM object. Safe to use with NULL
// pointers.
template <class T> void releaseComObject(T*& pT) {
if (pT) {
AUTO_COM_SUPPORT;
(pT)->Release();
pT = NULL;
}
}
最佳答案
从未发现该问题的重复场景。但是@Cheersandhth.-Alf 提到的智能指针的用户避免了这个问题。感谢您的反馈。
基本上使用下面的宏来定义智能指针,并移除所有对Release()
的引用
_COM_SMARTPTR_TYPEDEF(IMyInterface, __uuidof(IMyInterface));
关于c++ - 在 COM 对象上调用 Release 似乎永远不会返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37795268/