AtlUnadvise() の後で RefCount がデクリメントされないため、メモリ リークの問題が見つかりました。
テストコードは次のとおりです。
void CCppTesterDlg::OnBnClickedTextbtn()
{
CComObject<CManagedGuiEventSinkImpl> *pEventSink;
TestForm::ITestFormPtr pTestFormPtr( __uuidof(TestForm::TestForm) );
//Attach our COM event sink to the managed dialog to listen for keyboard and mouse events
if( CComObject<CManagedGuiEventSinkImpl>::CreateInstance(&pEventSink) == S_OK )
{
HRESULT hr = S_FALSE;
DWORD dwCookie = 0;
CComPtr<ManagedGuiEventInterface::IManagedGuiEventSink> pSink( pEventSink ); // ref count == 1
hr = AtlAdvise( pTestFormPtr, pSink, __uuidof(ManagedGuiEventInterface::IManagedGuiEventSink), &dwCookie );
// ref count == 2
//pTestFormPtr->OpenDialog();
//Detach the event sink after the modal dialog has been closed
hr = AtlUnadvise( pTestFormPtr, __uuidof(ManagedGuiEventInterface::IManagedGuiEventSink), dwCookie );
// ref count == 2
}
}
CManagedGuiEventSinkImpl クラスは、C# モジュールからイベントを取得するために使用されます。これまでのところ動作しますが、上記の pEventSink オブジェクトが適切に解放されないことがわかりました。
それらのクラスで見逃したことはありますか?
事前に感謝します。