Problem getting thumbnails
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Problem getting thumbnails

  1. #1
    Join Date
    Jul 2013
    Posts
    4

    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.

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,266

    Re: Problem getting thumbnails

    Welcome. 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!

    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.
    Last edited by 2kaud; July 6th, 2013 at 07:54 AM.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Jul 2013
    Posts
    4

    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.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,931

    Re: Problem getting thumbnails

    Quote Originally Posted by fafalone View Post
    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?
    Best regards,
    Igor

  5. #5
    Join Date
    Jul 2013
    Posts
    4

    Re: Problem getting thumbnails

    Quote Originally Posted by Igor Vartanov View Post
    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

  6. #6
    Join Date
    Apr 1999
    Posts
    27,423

    Re: Problem getting thumbnails

    Quote Originally Posted by fafalone View Post
    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

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,931

    Re: Problem getting thumbnails

    Quote Originally Posted by fafalone View Post
    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.
    Last edited by Igor Vartanov; July 12th, 2013 at 02:05 AM.
    Best regards,
    Igor

  8. #8
    Join Date
    Jul 2013
    Posts
    4

    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.
    Last edited by fafalone; July 22nd, 2013 at 03:40 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center