HBITMAP GetThumbnail(LPCTSTR FilePath)
{
IShellFolder* pDesktop = NULL;
IShellFolder* pSub = NULL;
IExtractImage* pIExtract = NULL;
LPITEMIDLIST pList = NULL;
Bitmap* pImg = NULL; TCHAR drive[MAX_PATH], dir[MAX_PATH], title[MAX_PATH], ext[MAX_PATH];
_tsplitpath_s(FilePath, drive, dir, title,ext);
_tcscat(drive, dir);
_tcscat(title, ext); // get the desktop directory
if (SUCCEEDED(SHGetDesktopFolder(&pDesktop)))
{   
// get the pidl for the directory
HRESULT hr = pDesktop->ParseDisplayName(NULL, NULL, drive, NULL, &pList, NULL);
if (FAILED(hr))
{
//throw new Exception(S"Failed to parse the directory name");
} // get the directory IShellFolder interface
hr = pDesktop->BindToObject(pList, NULL, IID_IShellFolder, (void**)&pSub);
if (FAILED(hr))
{
//throw new Exception(S"Failed to bind to the directory");
} // get the file's pidl
hr = pSub->ParseDisplayName(NULL, NULL, title, NULL, &pList, NULL);
if (FAILED(hr))
{
//throw new Exception(S"Failed to parse the file name");
} // get the IExtractImage interface
LPCITEMIDLIST pidl = pList;
hr = pSub->GetUIObjectOf(NULL, 1, &pidl, IID_IExtractImage,
NULL, (void**)&pIExtract);//在XP下调用之后pIExtract是NULL,在Vista下能正常执行 // set our desired image size
SIZE size;
size.cx = 1440;
size.cy = 1080;       if(pIExtract == NULL)

//return NULL;
}          HBITMAP hBmp = NULL; // The IEIFLAG_ORIGSIZE flag tells it to use the original aspect
// ratio for the image size. The IEIFLAG_QUALITY flag tells the 
// interface we want the image to be the best possible quality.
DWORD dwFlags = IEIFLAG_ORIGSIZE | IEIFLAG_QUALITY;     DWORD dwPriority = IEI_PRIORITY_MAX; OLECHAR pathBuffer[MAX_PATH];
hr = pIExtract->GetLocation(pathBuffer, MAX_PATH, &dwPriority, &size, 32, &dwFlags);         
if (FAILED(hr))
{
//throw new Exception(S"The call to GetLocation failed");
} hr = pIExtract->Extract(&hBmp); // It is possible for Extract to fail if there is no thumbnail image
// so we won't check for success here pIExtract->Release(); if (hBmp != NULL)
{
return hBmp;
}      
}
// Release the COM objects we have a reference to.
pDesktop->Release();
pSub->Release(); 
}