October 22nd, 2012, 02:47 PM
[RESOLVED] IShellDispatch: FolderItemVerbs? (Getting bizarre crash with CoUninitaialize!)
I hope this is the correct sub-forum to post this issue.
I'm having a very bizarre problem with the IShellDispatch COM interface, more specifically with the FolderItemVerbs that drives me nuts!
Calling FolderItemVerbs::Release() followed by CoUninitialze() will result in crash. It's clearly reproducible, but only happens 1 out of 10 times
Running the problematic code in a loop 100% reproduces the crash
Please see the example program:
Please download the *complete* example code is here:
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;
hr = pShellDispatch->NameSpace(vaDirectory, &pFolder);
if(FAILED(hr) || (pFolder == NULL))
iSuccess = -4;
hr = pFolder->ParseName(vaFileName, &pItem);
if(FAILED(hr) || (pItem == NULL))
iSuccess = -5;
hr = pItem->Verbs(&pVerbs);
if(FAILED(hr) || (pVerbs == NULL))
iSuccess = -6;
/* Here we would do something with the FolderItemVerbs */
pVerbs->Release(); //If this line is commented out, we don't get a crash, but a massive memory leak!
pVerbs = NULL;
pItem = NULL;
pFolder = NULL;
pShellDispatch = NULL;
iSuccess = 1;
static unsigned __stdcall ThreadProc(void* pArguments)
HRESULT hr = CoInitialize(NULL);
if((hr == S_OK) || (hr == S_FALSE))
threadParam_t *params = (threadParam_t*) pArguments;
params->returnValue = TestProc(params->pcDirectoryName, params->pcFileName);
if(threadParam_t *params = (threadParam_t*) pArguments)
params->returnValue = -10;
Please also note that I unambiguously tracked down to crash to FolderItemVerbs, because if I never create the FolderItemVerbs object, the crash is gone immediately.
Also if I never call "pVerbs->Release()" before CoUninitialize() the crash is gone too, but this will result in a massive memleak, obviously.
Another strange thing is that the crash will NOT happen, if I run the program under the Debugger! But I can run the program, wait for the crash and then let the Debugger handle the crash.
Unfortunately the Stack Trace that I get then doesn't help much:
I don't think I'm doing anything wrong here. I have checked the code over and over again in the last two days. So this all seems to be a bug in FolderItemVerbs!
Has anybody encountered this before and/or can confirm that this is a bug in FolderItemVerbs? Also, is there any workaround for the problem?
Thanks in advance !!!
Last edited by MuldeR2; October 23rd, 2012 at 07:27 AM.
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!