Jose's Read Only Forum 2023

IT-Consultant: José Roca (PBWIN 10+/PBCC 6+) (Archive only) => Discussion => Topic started by: Rick Kelly on December 13, 2011, 05:07:56 AM

Title: Special Folders
Post by: Rick Kelly on December 13, 2011, 05:07:56 AM
Are they any plans afoot to "wrap" the "wrappers" for the special folders api since it changed a bit with Vista. Now we have this public folder business.

Rick Kelly
Title: Re: Special Folders
Post by: José Roca on December 13, 2011, 07:03:30 AM
The current ones work in all Windows versions. Yu can find them in AfxShell.inc.

Title: Re: Special Folders
Post by: Rick Kelly on December 13, 2011, 10:22:46 AM
Quote from: José Roca on December 13, 2011, 07:03:30 AM
The current ones work in all Windows versions. Yu can find them in AfxShell.inc.

I was looking for \users\public, i.e. FOLDERID_Public with the newer api.

Rick Kelly
Title: Re: Special Folders
Post by: José Roca on December 13, 2011, 08:26:47 PM
Well, I'm going to add this wrapper to AfxShell.inc


' ========================================================================================
' Retrieves the path of an special folder. Windows Vista/Windows 7.
' ========================================================================================
FUNCTION AfxGetKnowFolder (BYREF rfid AS GUID, OPTIONAL BYVAL dwFlags AS DWORD, BYVAL hToken AS DWORD) AS WSTRING
   LOCAL pidl AS DWORD                     ' // Pointer to an item identifier list (PIDL)
   LOCAL wszPath AS WSTRINGZ * %MAX_PATH   ' // Folder's path
   IF SHGetKnownFolderIDList(rfid, dwFlags, hToken, pidl) = %S_OK THEN
      SHGetPathFromIDListW BYVAL pidl, wszPath
      CoTaskMemFree pidl
      FUNCTION = wszPath
   END IF
END FUNCTION
' ========================================================================================

Title: Re: Special Folders
Post by: Rick Kelly on December 14, 2011, 04:41:59 AM
Quote from: José Roca on December 13, 2011, 08:26:47 PM
Well, I'm going to add this wrapper to AfxShell.inc


' ========================================================================================
' Retrieves the path of an special folder. Windows Vista/Windows 7.
' ========================================================================================
FUNCTION AfxGetKnowFolder (BYREF rfid AS GUID, OPTIONAL BYVAL dwFlags AS DWORD, BYVAL hToken AS DWORD) AS WSTRING
   LOCAL pidl AS DWORD                     ' // Pointer to an item identifier list (PIDL)
   LOCAL wszPath AS WSTRINGZ * %MAX_PATH   ' // Folder's path
   IF SHGetKnownFolderIDList(rfid, dwFlags, hToken, pidl) = %S_OK THEN
      SHGetPathFromIDListW BYVAL pidl, wszPath
      CoTaskMemFree pidl
      FUNCTION = wszPath
   END IF
END FUNCTION
' ========================================================================================


That looks like the ticket. Will have to check the OS Version before referencing it?

Rick Kelly
Title: Re: Special Folders
Post by: José Roca on December 14, 2011, 04:47:03 AM
If you intend to use it with XP and below, yes. However, with the OSEs it's better to use the existing AfxGetSpecialFolderLocation function, since neither SHGetKnownFolderID nor the new folders aren't available in them.
Title: Re: Special Folders
Post by: José Roca on December 14, 2011, 04:52:07 AM
...and if used with XP and below, then you will have to replace the call to SHGetKnownFolderIDList with LoadLibrary/Call DWORD/FreeLibrary.

In short, don't use the above AfxGetKnowFolder wrapper function with XP or below.
Title: Re: Special Folders
Post by: Rick Kelly on December 14, 2011, 05:10:12 AM
Quote from: José Roca on December 14, 2011, 04:52:07 AM
...and if used with XP and below, then you will have to replace the call to SHGetKnownFolderIDList with LoadLibrary/Call DWORD/FreeLibrary.

In short, don't use the above AfxGetKnowFolder wrapper function with XP or below.

OK, I get it. My app is for XP or later. There is still so many copies of XP out there, I though it a good idea to at least include them in the app I'm working on.

Rick Kelly
Title: Re: Special Folders
Post by: José Roca on December 14, 2011, 05:24:58 AM
If it has to work with XP, don't use anything that requires Vista or Windows 7.