• Welcome to Jose's Read Only Forum 2023.
 

Special Folders

Started by Rick Kelly, December 13, 2011, 05:07:56 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rick Kelly

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

José Roca

The current ones work in all Windows versions. Yu can find them in AfxShell.inc.


Rick Kelly

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

José Roca

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
' ========================================================================================


Rick Kelly

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

José Roca

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.

José Roca

...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.

Rick Kelly

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

José Roca

If it has to work with XP, don't use anything that requires Vista or Windows 7.