Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Mon, 7 Jul 2008 00:09:01 -0700,    group: microsoft.public.platformsdk.shell        back       


problem with reading Thumbs.db in windows shell   
Dear,

I am tring to read thumbs.db file format and I hear that windows shell can 
read such format. So I try to write the following code but some problem faces 
me:

*******************************
STDMETHODIMP CFileThumbExtract::ExtractThumbnail(HBITMAP *phBitmap)
{ 
   LPITEMIDLIST localPidl;
   //const SIZE* prgSize;
   typedef IExtractImage * LPEXTRACTIMAGE;
   OLECHAR wszPathBuffer[MAX_PATH];
   DWORD dwPriority = 0; // IEI_PRIORITY_NORMAL is defined nowhere!
   DWORD dwFlags = IEIFLAG_SCREEN;
   HBITMAP hBmpImage = NULL;
   LPSHELLFOLDER psfFolder = NULL;
   LPEXTRACTIMAGE pIExtract = NULL;
   HRESULT hr;
   ULONG chEaten = 0;
   wchar_t buf[100];

   SHGetDesktopFolder(&psfFolder);

   memcpy(buf, L"c:\\test\\Thumbs.db", lstrlenW(L"c:\\test\\Thumbs.db") );

   hr = psfFolder->ParseDisplayName(NULL, NULL, buf,
 &chEaten,
 &localPidl,
 NULL);

   hr = psfFolder->GetUIObjectOf(NULL, 1, (const ITEMIDLIST**)&localPidl, 
IID_IExtractImage,
                                 NULL, (void**)&pIExtract);

   hr = pIExtract->GetLocation(wszPathBuffer, MAX_PATH, &dwPriority,
                               (SIZE*)28672, NULL, &dwFlags);

   if(NULL == pIExtract)
      return NULL;

   if(NOERROR == hr) hr = pIExtract->Extract(&hBmpImage);
   pIExtract->Release();

   return hBmpImage;
}
*****************************

*Is that the way to read such format? Can I read all thumbnail imaes?

*In the (psfFolder->GetUIObjectOf) function the programe crashes. Any idea 
what is the problem here?

thanks alot
date: Mon, 7 Jul 2008 00:09:01 -0700   author:   Amer Huzayen Amer

Re: problem with reading Thumbs.db in windows shell   
Amer Huzayen wrote:
> I am tring to read thumbs.db file format and I hear that windows
> shell can read such format. 

Windows XP does not provide programmatic access to its thumbnail cache, as far as I know. You can obtain thumbnails for specific files via IExtractImage, but you can't ask for thumbnails from a Thumbs.db file.

>   wchar_t buf[100];
> 
>   memcpy(buf, L"c:\\test\\Thumbs.db",
> lstrlenW(L"c:\\test\\Thumbs.db") ); 

Bad move. You copied the first 17 bytes of the string, but each wide char takes two bytes, so the string is actually 34 bytes long. Also you didn't include a zero terminator. So ParseDisplayName fails because it received an invalid path, and then your program crashes because you didn't check the HRESULT.

-- 
Jim Barry, Microsoft MVP
date: Mon, 7 Jul 2008 11:17:08 +0100   author:   Jim Barry

Re: problem with reading Thumbs.db in windows shell   
thanks alot for your answer.

please before that let me now if I will get the result I need which is the 
images in the thumbs.db?

I notied that and I wrote another code, but the HRESULT return (0x80070002) 
this error number after calling (psfWorkDir->GetUIObjectOf) function in the 
below code:

*******************************

HRESULT CFileThumbExtract::CreateThumbnail(DWORD dwWidth, DWORD dwHeight, 
HBITMAP* pThumbnail)
{
   LPITEMIDLIST pidlItems = NULL, pidlURL = NULL, pidlWorkDir = NULL;
   HRESULT hr;
   WCHAR pszPath[MAX_PATH];
   DWORD dwPriority = 0, dwFlags = IEIFLAG_ASPECT;
   SIZE size = { dwWidth, dwHeight };
   IExtractImage* peiURL = NULL;
   IShellFolder* psfDesktop = NULL;
   IShellFolder* psfWorkDir = NULL;

	basic_string<WCHAR> wsDir,wsFile,wsTempFile;

   hr = SHGetDesktopFolder(&psfDesktop);
   if(FAILED(hr)) goto OnExit;

   // create shortcut if URL
	if(PathIsURLW(m_wsPath.c_str())) {
      wsTempFile = m_wsTempPath; wsTempFile += TEMP_URL;
      if(!CreateURLShortcut(m_wsPath.c_str(), wsTempFile.c_str())) goto 
OnExit;
      wsDir = m_wsTempPath;
      wsFile = TEMP_URL;
   }
   else {
      wsDir = m_wsDir;
      wsFile = m_wsFile;
   }
   // get working directory
	wcscpy(m_wsBuffer,wsDir.c_str());
   hr = psfDesktop->ParseDisplayName(NULL, NULL, m_wsBuffer, NULL, 
&pidlWorkDir, NULL);
   if(FAILED(hr)) goto OnExit;

   hr = psfDesktop->BindToObject(pidlWorkDir, NULL, IID_IShellFolder, 
(LPVOID*)&psfWorkDir);
   if(FAILED(hr)) goto OnExit;

   psfDesktop->Release();
   psfDesktop = NULL;
   m_pMalloc->Free(pidlWorkDir);
   pidlWorkDir = NULL;

   // retrieve link information
	wcscpy(m_wsBuffer,wsFile.c_str());
   hr = psfWorkDir->ParseDisplayName(NULL, NULL, m_wsBuffer, NULL, &pidlURL, 
NULL);
   if(FAILED(hr)) goto OnExit;

   // query IExtractImage
   hr = psfWorkDir->GetUIObjectOf(NULL, 2, (LPCITEMIDLIST*)&pidlURL, 
IID_IExtractImage, NULL, (void**)&peiURL);
   if(FAILED(hr)) goto OnExit;

   // define thumbnail properties
   hr = peiURL->GetLocation(pszPath, MAX_PATH, &dwPriority, &size, 16, 
&dwFlags);
   if(FAILED(hr)) goto OnExit;

   // generate thumbnail
   hr = peiURL->Extract(pThumbnail);
   if(FAILED(hr)) goto OnExit;

   // clean-up IExtractImage
   peiURL->Release();
   peiURL = NULL;

OnExit:

   // free allocated structures
   if(peiURL != NULL) peiURL->Release();
   if(pidlURL != NULL) m_pMalloc->Free(pidlURL);
   if(pidlWorkDir != NULL) m_pMalloc->Free(pidlWorkDir);
   if(psfDesktop != NULL) psfDesktop->Release();
   if(psfWorkDir != NULL) psfWorkDir->Release();
   return hr;
}

***********************************
date: Mon, 7 Jul 2008 06:30:01 -0700   author:   Amer Huzayen

Re: problem with reading Thumbs.db in windows shell   
Amer Huzayen wrote:
> I notied that and I wrote another code, but the HRESULT return
> (0x80070002) this error number after calling
> (psfWorkDir->GetUIObjectOf) function in the below code:

What type of file are you trying to get a thumbnail for? That's the error code I would expect to see if the file class didn't have a thumbnail handler.

-- 
Jim Barry, Microsoft MVP
date: Mon, 7 Jul 2008 19:36:06 +0100   author:   Jim Barry

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us