GetSystemPath - Delphi XE

0

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.

0
Path: LPSTR;

daj po prostu Path:PChar;

0

Polecam użyć to tego bezpośrednio rejestru. Przykład znajdziesz gdzieś, a jak nie to wrzucę mój skrypt.

1 użytkowników online, w tym zalogowanych: 0, gości: 1