Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get folder path from Known folder GUID in Delphi

I have a KNOWNFOLDERID and I would like to know the corresponding path like C:....\folder.

KNOWNFOLDERID can be found here. http://msdn.microsoft.com/en-us/library/bb762584%28VS.85%29.aspx

I d like to use win api (I don't want to build an array with all KNOWNFOLDERID and paths).

Thanks

like image 983
user382591 Avatar asked Feb 10 '13 20:02

user382591


1 Answers

Simply call the SHGetKnownFolderPath API function.

Since this function was added in Vista, it won't be declared in the library units that shipped with Delphi 7. So you'd need to declare it yourself.

type
  KNOWNFOLDERID = TGuid;

function SHGetKnownFolderPath(
  const rfid: KNOWNFOLDERID;
  dwFlags: DWORD; 
  hToken: THandle; 
  out ppszPath: PWideChar
): HResult; stdcall; external 'Shell32.dll';

Now, since this function was added in Vista, attempts to call it on XP will lead to failures. So, I would recommend dealing with this by using CSIDL functions rather than the Vista known folder APIs.

like image 95
David Heffernan Avatar answered Nov 20 '22 10:11

David Heffernan