I'm trying to make use of the IExtractImage interface provided by the Windows Shell API.
I realize that this might be out dated, but I need my code to work with Windows XP, Vista, and Win7.
The following unfinished code successfully executes every shell object method up to GetUIObjectOf which fails every time.
I can't figure out what's wrong. Help would be appreciated.
bool ExtractImage(char* filePath, char* fileName, char* outputBuffer){
string mbsPath(filePath), mbsName(fileName);
wstring wcsPath(mbsPath.size(),'\0'), wcsName(mbsName.size(),'\0');
mbstowcs(&(wcsPath[0]),mbsPath.c_str(),mbsPath.size());
mbstowcs(&(wcsName[0]),mbsName.c_str(),mbsName.size());
bool returnVal = true;
IShellFolder *pDesktop = NULL, *pSubfolder = NULL;
IExtractImage *pExtractor = NULL;
LPITEMIDLIST pIDL;
try{
if( SHGetDesktopFolder(&pDesktop) != S_OK ){ throw 0; }
if( pDesktop->ParseDisplayName( NULL, NULL, (LPWSTR)wcsPath.c_str(), NULL,
&pIDL, NULL ) != S_OK ){ throw 0; }
if( pDesktop->BindToObject( pIDL, NULL, IID_IShellFolder,
(void**)&pSubfolder ) != S_OK ){ throw 0; }
if( pSubfolder->ParseDisplayName( NULL, NULL, (LPWSTR)wcsName.c_str(),
NULL, &pIDL, NULL ) != S_OK ){ throw 0; }
if( pSubfolder->GetUIObjectOf( NULL, 1, (LPCITEMIDLIST*)&pIDL,
IID_IExtractImage, NULL, (void**)&pExtractor ) != S_OK ){ throw 0; }
} catch (...) {
returnVal = false;
}
if(pExtractor != NULL){pExtractor->Release();}
if(pSubfolder != NULL){pSubfolder->Release();}
if(pDesktop != NULL){pDesktop->Release();}
return returnVal;
}