Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C++
bool ExtractImage(char* filePath, char* fileName, char* outputBuffer){
    
    //convert the input strings to wide strings
    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{

        //Get interface object for root (desktop) folder
        if( SHGetDesktopFolder(&pDesktop) != S_OK ){ throw 0; }

        //Get the pIDL for the subfolder
        if( pDesktop->ParseDisplayName( NULL, NULL, (LPWSTR)wcsPath.c_str(), NULL,
          &pIDL, NULL ) != S_OK ){ throw 0; }

        //Get the interface for the subfolder
        if( pDesktop->BindToObject( pIDL, NULL, IID_IShellFolder,
          (void**)&pSubfolder ) != S_OK ){ throw 0; }

        //Get the pIDL for the file
        if( pSubfolder->ParseDisplayName( NULL, NULL, (LPWSTR)wcsName.c_str(),
          NULL, &pIDL, NULL ) != S_OK ){ throw 0; }

        //Get the Extractor interface
        if( pSubfolder->GetUIObjectOf( NULL, 1, (LPCITEMIDLIST*)&pIDL,
          IID_IExtractImage, NULL, (void**)&pExtractor ) != S_OK ){ throw 0; }

    } catch (...) {

        returnVal = false;

    }
    
    //cleanup
    if(pExtractor != NULL){pExtractor->Release();}
    if(pSubfolder != NULL){pSubfolder->Release();}
    if(pDesktop != NULL){pDesktop->Release();}
    
    return returnVal;
}
Posted

1 solution

JeffString wrote:
I can't figure out what's wrong

Because you didn't check the HRESULT return value of the method: it should give you meaningful info.
 
Share this answer
 
Comments
JeffString 14-Nov-11 23:48pm    
I am not familiar with the HRRESULT error codes and the reference I had was a condensed list that didn't help. I eventually found a more expansive list at http://msdn.microsoft.com/en-us/library/cc704587%28v=prot.10%29.aspx

They should make it easier to find, but it did lead me to the problem. I needed to add a call to CoInitialize.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900