1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
| interface : : function SHGetKnownFolderPath(rfid: TGUID; dwFlags: DWORD; hToken: THandle; var ppszPath: IntPtr): HRESULT; function SHGetKnownFolderPathA(rfid: TGUID; dwFlags: DWORD; hToken: THandle; var ppszPath: IntPtr): HRESULT; function SHGetKnownFolderPathW(rfid: TGUID; dwFlags: DWORD; hToken: THandle; var ppszPath: IntPtr): HRESULT; : : implementation : : const Shell32Dll = 'Shell32.dll';
[SuppressUnmanagedCodeSecurity, DllImport(Shell32Dll, CharSet = CharSet.Auto, SetLastError = True, EntryPoint = 'SHGetKnownFolderPath')] function SHGetKnownFolderPath; external; [SuppressUnmanagedCodeSecurity, DllImport(Shell32Dll, CharSet = CharSet.Ansi, SetLastError = True, EntryPoint = 'SHGetKnownFolderPathA')] function SHGetKnownFolderPathA; external; [SuppressUnmanagedCodeSecurity, DllImport(Shell32Dll, CharSet = CharSet.Unicode, SetLastError = True, EntryPoint = 'SHGetKnownFolderPathW')] function SHGetKnownFolderPathW; external; : : function GetFolderPath(Folder: TGUID): String; var Buffer: IntPtr; Res: HRESULT; begin Res := SHGetKnownFolderPath(Folder, 0, 0, Buffer); OleCheck(Res); Result := Marshal.PtrToStringAuto(Buffer); if Assigned(Buffer) then CoTaskMemFree(Buffer); end; |