我调用此函数获得系统图标,显示在ClistCtrl里,第一次是正常的。但是第二次调用会失败。有大神能解决吗。
             膜拜大神,感激不尽啊。
代码如下。 HIMAGELIST  hSystemSmallImageList;
SHFILEINFO    ssfi; //CoInitialize
hSystemSmallImageList = (HIMAGELIST)SHGetFileInfo( strTemp, 0, &ssfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | LVS_SHAREIMAGELISTS); 

m_ImageList.Attach( hSystemSmallImageList );
m_ImageList是 CImageList类型的

解决方案 »

  1.   

    If SHGetFileInfo returns an icon handle in the hIcon member of the SHFILEINFO structure pointed to by psfi, you are responsible for freeing it with DestroyIcon when you no longer need it.
      

  2.   


    用完系统图标后调用下列语句:
     
    m_ImageList.Detach();
      

  3.   


    我用图片框测试不关显示几次,都没问题.
    代码如下:HIMAGELIST hSystemSmallImageList;
    SHFILEINFO ssfi;
    TCHAR strTemp[128];
    CStatic *pImage;
    //CoInitialize
    hSystemSmallImageList = (HIMAGELIST)SHGetFileInfo( strTemp, 0, &ssfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | LVS_SHAREIMAGELISTS);  m_ImageList.Attach( hSystemSmallImageList );
    pImage = (CStatic *)GetDlgItem(IDC_STATIC);pImage->SetIcon(m_ImageList.ExtractIcon(1));ImageList_Destroy(hSystemSmallImageList);m_ImageList.Detach();
      

  4.   

    是我2了 , 把那个hSystemSmallImageList释放掉了