Last updated:
31. October 2001

User Interface Programming

(Start main menu) Home ­ Articles ­ Book ­ Resources (End main menu)

getLongPathName.cpp: Listing 27


(Start sub-menu)

Table of Contents

Cover

Sample Chapter

Changelog


 

Feedback…

My blog »

(End sub-menu)

Programming Industrial Strength Windows (cover)

/*
 * $Header: /Book/getLongPathName.cpp 11    11.07.01 14:48 Oslph312 $
 */
 
#include "precomp.h"
#include "AutoComReference.h"
#include "AutoShellObject.h"
#include "utils.h"
#include "os.h"
#include <shlobj.h>
 
 
// LATER: Create a Filename class; handle named streams properly.
String getLongPathName( const String& strShort ) {
 
   String strLong;
 
   AutoComReference< IShellFolder > pShellFolder;
   HRESULT hres = SHGetDesktopFolder( &pShellFolder );
   if ( SUCCEEDED( hres ) ) {
 
#ifdef UNICODE
#define wszShort const_cast< LPWSTR >( strShort.c_str() )
#else
      PATHNAMEW wszShort = { 0 };
      multiByteToWideChar( strShort.c_str(), wszShort );
#endif
 
      ULONG ulEaten = 0;
      ULONG ulAttributes = 0;
      AutoShellObject< ITEMIDLIST > pidl;
      hres = pShellFolder->ParseDisplayName( HWND_DESKTOP, 0,
         wszShort, &ulEaten, &pidl, &ulAttributes );
      if ( SUCCEEDED( hres ) ) {
         strLong = getPathFromIDList( pidl );
      }
   }
 
   // In case of failure, keep the short name:
   // TODO: Check error code -2147467259 (0x80004005) (Unspecified error)
   if ( !SUCCEEDED( hres ) || strLong.empty() ) {
      strLong = strShort;
   }
 
   return strLong;
}
 
// end of file

(Start bottom menu)

TopHomeArticlesBookResources
Win­dows De­vel­oper Maga­zineR&D BooksCMP Books
Amazon.comAmazon.co.ukContact Petter Hesselberg

(End bottom menu)

Chapter 7 Listings

createNewFile.cpp

getLongPathName.cpp

resolveName.cpp

activateOldInstance.cpp

ArgumentList.h

ArgumentList.cpp

init.cpp