Problem getting thumbnails
Hi everyone, I'm very new to C++ so please go easy on me. I'm using a very simple DLL to get a thumbnail for a file and add it to an imagelist. The problem is, whenever I pass a pidl that points to a text document (*.txt), something goes wrong and the development environment for the app using the DLL freezes. Any other file type successfully returns either the thumbnail or file icon.
It's a very short code; not sure what could be going wrong.
Code:
extern "C" RNTHUMB_API HRESULT __stdcall AddTohIML(HIMAGELIST himl, PCIDLIST_ABSOLUTE pidlSrc, int cxThumb, int cyThumb, int lFlags)
{
int hpos1 = -1;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
// Getting the IShellItemImageFactory interface pointer for the file.
IShellItemImageFactory *pImageFactory;
hr = SHCreateItemFromIDList(pidlSrc, IID_PPV_ARGS(&pImageFactory));
if (SUCCEEDED(hr))
{
SIZE size = { cxThumb, cyThumb };
HBITMAP hbmp;
hr = pImageFactory->GetImage(size, (SIIGBF)lFlags, &hbmp);
if (SUCCEEDED(hr))
{
hpos1 = ImageList_Add(himl, hbmp, NULL);
return (HRESULT)hpos1;
DeleteObject(hbmp);
}
pImageFactory->Release();
}
}
CoUninitialize();
return (HRESULT)hpos1;
};
Using VS2008.
Re: Problem getting thumbnails
Welcome.:wave: We are a friendly bunch of gurus who'll try to help, guide and advise the best we can.
You've passed the first test - used proper code tags!:thumb:
Code:
if (SUCCEEDED(hr)) {
hpos1 = ImageList_Add(himl, hbmp, NULL);
return (HRESULT)hpos1;
DeleteObject(hbmp);
}
I haven't used those image factory functions so can't really comment on the problem - but does the .txt file contain images or anything unusual? Also, the DeleteObject(hbmp) function will never be called as it is after the return statement.
Re: Problem getting thumbnails
Nope, it's just a plain old text file. And this is for all text files, not a specific one. There might be other file types; I haven't done an exhaustive search, but so far that's it.
Re: Problem getting thumbnails
Quote:
Originally Posted by
fafalone
The problem is, whenever I pass a pidl that points to a text document (*.txt), something goes wrong and the development environment for the app using the DLL freezes.
Are you intending to fix VS2008?
Re: Problem getting thumbnails
Quote:
Originally Posted by
Igor Vartanov
Are you intending to fix VS2008?
I'm using the DLL from a VB6 program on Win7 x64. Please hold the snickering, legacy programming has its place :)
Re: Problem getting thumbnails
Quote:
Originally Posted by
fafalone
I'm using the DLL from a VB6 program on Win7 x64. Please hold the snickering, legacy programming has its place :)
What happens if you don't debug it and just let the application run? Does your program work? You need to see if it is the development environment, or your application truly has an error.
Regards,
Paul McKenzie
Re: Problem getting thumbnails
Quote:
Originally Posted by
fafalone
Please hold the snickering, legacy programming has its place :)
Your case is definitely not about legacy programming. It's about, in case your explanation is correct, development environment freezing under certain circumstances. If I were you, I would either change the IDE or find some other way for debugging this code fragment. Or make sure my VS has every single recommended service pack installed, and if it does, I would send a complaint to MS support and see what they be able to come up with.
Re: Problem getting thumbnails
Ok, the compiled EXE just hangs like the IDE did. 0 CPU usage too.
I found a way to work around it; specify SIIGBF_THUMBNAILONLY for only those files that support it. Any other set of flags doesn't hang. But I can't just use other flags because it doesn't return the thumbnail for image files unless that flag is there (it should, but doesn't, probably because they're disabled in explorer).
So I guess that's the easy way. But is there a simple way to determine which file types have support for IShellImageFactory? Since additional preview handlers can be installed it's not a static list. And the only example I could seem to find was monstrously complicated (to someone who doesn't know C++) and didn't actually return extensions, only types, for some files.