I have a very strange problem with the IShellDispatch COM interface, more specifically with the FolderItemVerbs object that turns me on!
A call to FolderItemVerbs :: Release (), followed by CoUninitialze (), will fail. It is clearly reproducible, but only once out of 10 times.
Error - error "0xC0000005: access violation". Running the problem code in a 100% cycle sooner or later leads to a failure: - (
See an example program:
static int TestProc(const TCHAR *pcDirectoryName, const TCHAR *pcFileName) { int iSuccess = 0; IShellDispatch *pShellDispatch = NULL; Folder *pFolder = NULL; FolderItem *pItem = NULL; FolderItemVerbs *pVerbs = NULL; HRESULT hr = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void**)&pShellDispatch); if(FAILED(hr) || (pShellDispatch == NULL)) { iSuccess = -3; return iSuccess; } variant_t vaDirectory(pcDirectoryName); hr = pShellDispatch->NameSpace(vaDirectory, &pFolder); if(FAILED(hr) || (pFolder == NULL)) { iSuccess = -4; pShellDispatch->Release(); return iSuccess; } variant_t vaFileName(pcFileName); hr = pFolder->ParseName(vaFileName, &pItem); if(FAILED(hr) || (pItem == NULL)) { iSuccess = -5; pFolder->Release(); pShellDispatch->Release(); return iSuccess; } hr = pItem->Verbs(&pVerbs); if(FAILED(hr) || (pVerbs == NULL)) { iSuccess = -6; pItem->Release(); pFolder->Release(); pShellDispatch->Release(); return iSuccess; } pVerbs->Release(); pVerbs = NULL;
Please download the full sample code here: http://pastie.org/private/0xsnajpia9lsmgnlf2afa
Also note that I have explicitly tracked it to failure before FolderItemVerbs , because if I never create a FolderItemVerbs object, the crash will disappear immediately.
Also, if I never call "pVerbs-> Release ()" before CoUninitialize (), the failure will also disappear, but this will lead to a massive memleak, obviously.
Another strange thing: a crash will not happen if I run the program under Debugger! But I can run the program, wait for the crash, and then let the debugger deal with the failure.
Unfortunately, the stack trace I get doesn't help much: http://pastie.org/private/cuwunlun2t5dc5lembpw
I do not think that I am doing something wrong. I have been checking the code again and again over the past two days. So all this seems to be a mistake in FolderItemVerbs!
Has anyone come across this before and / or can confirm that this is a bug in FolderItemVerbs? Also, is there a workaround?
Thanks in advance!