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.