Mam funkcję, którą używałem w Delphi 7:
function GetSystemPath(Folder: Integer): string;
var
PIDL: PItemIDList;
Path: LPSTR;
AMalloc: IMalloc;
begin
Path := StrAlloc(MAX_PATH);
SHGetSpecialFolderLocation(0, Folder, PIDL);
if SHGetPathFromIDList(PIDL, Path) then
Result := Path;
SHGetMalloc(AMalloc);
AMalloc.Free(PIDL);
StrDispose(Path);
end;
Przesiadłem się na Delphi XE i ta sama funkcja nie chciała się skompilować. Według błędów w konsoli (różnica typów) zrobiłem modyfikację:
function GetSystemPath(Folder: Integer): string;
var
PIDL: PItemIDList;
Path: LPSTR;
AMalloc: IMalloc;
begin
Path := PAnsiChar(StrAlloc(MAX_PATH));
SHGetSpecialFolderLocation(0, Folder, PIDL);
if SHGetPathFromIDList(PIDL, PWideChar(Path)) then
Result := String(Path);
SHGetMalloc(AMalloc);
AMalloc.Free(PIDL);
StrDispose(Path);
end;
Program skompilował się, ale nie zwraca poprawnej ścieżki, tylko samą literę "C".
Proszę o pomoc.