Win Shell API GetUIObjectOf方法出现问题 [英] Problem with Win Shell API GetUIObjectOf Method

查看:204
本文介绍了Win Shell API GetUIObjectOf方法出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Windows Shell API提供的IExtractImage接口.

我意识到这可能已经过时,但是我需要我的代码才能与Windows XP,Vista和Win7一起使用.

以下未完成的代码成功地执行了每个Shell对象方法,直到GetUIObjectOf都失败了.

我不知道怎么了.帮助将不胜感激.

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){
    
    //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;
}

推荐答案

JeffString写道:
JeffString wrote:

我不能找出问题所在


因为您没有检查方法的HRESULT返回值:它应该为您提供有意义的信息.


Because you didn''t check the HRESULT return value of the method: it should give you meaningful info.


这篇关于Win Shell API GetUIObjectOf方法出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆