none
为什么OleLoadPicture函数会调用失败 RRS feed

  • 常规讨论

  • 使用下面一个函数打开一幅png图像:

    static HBITMAP LoadAnImage(const char* FileName) 
    { // Use IPicture stuff to use JPG / GIF files
    IPicture* p = NULL;
    IStream* s = NULL;
    IPersistStream* ps = NULL;
     HGLOBAL hG; void* pp = NULL;
     FILE* fp;
    // Read file in memory
    fp = fopen(FileName,"rb");
    if (!fp) return NULL; fseek(fp,0,SEEK_END);
     int fs = ftell(fp);
    fseek(fp,0,SEEK_SET);
     hG = GlobalAlloc(GPTR,fs);
     if (!hG)
    {
    fclose(fp);
    return NULL; }
     pp = (void*)hG;
    fread(pp,1,fs,fp);
     fclose(fp);
     // Create an IStream so IPicture can
    CreateStreamOnHGlobal(hG,false,&s);
    if (NULL==s) {
    GlobalFree(hG);
    return NULL;
    }

     HRESULT hr = OleLoadPicture(s,0,false,IID_IPicture,(void**)&p);

     if (S_OK!=hr)
    {
     return NULL;
     }

    if (NULL==p)
     { s->Release();
    GlobalFree(hG);
    return NULL; }
    s->Release();
    GlobalFree(hG);
    HBITMAP hB = NULL;
    p->get_Handle((unsigned int*)&hB);
    // Copy the image. Necessary, because upon p's release,
    // the handle is destroyed.
    HBITMAP hBB = (HBITMAP)CopyImage(hB,IMAGE_BITMAP,0,0, LR_COPYRETURNORG);
    p->Release();
    return hBB;
    }

         但是在调用OleLoadPicture函数时失败,返回值是
    hr = -2146827807,16进制数就是0x800A01E1

      查了一些资料:

    OleLoadPictureFile

    Return code
    Description

    S_OK
    The method completed successfully.

    CTL_E_INVALIDPICTURE (0x800A01E1)
    Invalid picture file.


      为什么会调用失败呢?如何解决?我的编译环境是:

    VS 2005, Win XP + sp3。

     

     

     

     

     

     

     

     

     


    前无古人,后无来者
    2010年5月8日 9:41