Also mit CSIDL_DESKTOP geht es:
Delphi-Quellcode:
uses
ShlObj,
ActiveX;
function GetShellFolder(CSIDL: integer):
string;
var
pidl : PItemIdList;
FolderPath :
string;
SystemFolder : Integer;
Malloc : IMalloc;
begin
Malloc :=
nil;
FolderPath := '
';
SHGetMalloc(Malloc);
if Malloc =
nil then
begin
Result := FolderPath;
Exit;
end;
try
SystemFolder := CSIDL;
if SUCCEEDED(SHGetSpecialFolderLocation(0, SystemFolder, pidl))
then
begin
SetLength(FolderPath, max_path);
if SHGetPathFromIDList(pidl, PChar(FolderPath))
then
begin
SetLength(FolderPath, length(PChar(FolderPath)));
end;
end;
Result := FolderPath;
finally
Malloc.Free(pidl);
end;
end;
const
CSIDL_MYDOCUMENTS = $000C;
CSIDL_DESKTOP = $0000;
procedure TForm1.Button1Click(Sender: TObject);
begin
showMessage(GetShellFolder(CSIDL_DESKTOP) + '
\test.txt');
end;
Mit CSIDL_MYDOCUMEBNTS bekomme ich das gleiche Ergebnis wie du.