SHGetFileInfo 调用3000多次后失败,写了代码,重现了这个错误,

gaoyue_qq_1664507529 2012-02-27 03:51:51
void CaDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
CoInitialize(NULL);
long num=0;
while(true)
{

SHFILEINFO FileInfo;
FileInfo.hIcon=0;
memset(&FileInfo,0,sizeof(SHFILEINFO));

SHGetFileInfo(L"C:\\", 0, &FileInfo, sizeof(FileInfo),SHGFI_ICON);
if(FileInfo.hIcon==0)
{
CString str;
str.Format(L"调用%d次后失败",num);
MessageBox(str);
break;
}else
{
//CloseHandle(FileInfo.hIcon);//写上这句话,也是不行的,
}


num++;
}




CoUninitialize();



}

求解决办法。。。。。。我要得到文件的图标句柄,所以这个函数要调用很多次。
...全文
88 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
thanks run ok new!
gameslq 2012-02-27
  • 打赏
  • 举报
回复
进程内存耗尽?
CloseHandle(FileInfo.hIcon改为
DestroyIcon(FileInfo.hIcon);//写上这句话,也是不行的
msdn:

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.
xuanfeng007 2012-02-27
  • 打赏
  • 举报
回复
MSDN解释:
You should call this function from a background thread. Failure to do so could cause the UI to stop responding.

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.

MSDN例子,
LPITEMIDLIST pidl = NULL;
hr = SHGetFolderLocation(NULL, CSIDL_BITBUCKET, NULL, 0, &pidl);

if (SUCCEEDED(hr))
{
SHFILEINFOW sfi = {0};
hr = SHGetFileInfo((LPCTSTR)pidl,
-1,
&sfi,
sizeof(sfi),
SHGFI_PIDL | SHGFI_DISPLAYNAME)

if (SUCCEEDED(hr))
{
// The display name is now held in sfi.szDisplayName.
}
}

ILFree(pidl);

仅供参考!

可能你已经看过了,建议模仿例子,开个线程跑下,上面说如果不需要的时候调用 DestroyIcon, 试下呢。

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧