uses
ActiveX, ShlObj, SHDocVw, ComObj;
function PathToPIDL(
const Path:
string): PItemIDList;
const
SFGAO_STREAM = $00400000;
var
Count: ULONG;
Attributes: ULONG;
ShellFolder: IShellFolder;
begin
OleCheck(SHGetDesktopFolder(ShellFolder));
Attributes := SFGAO_FOLDER
or SFGAO_STREAM;
OleCheck(ShellFolder.ParseDisplayName(0,
nil, PWideChar(WideString(Path)), Count, Result, Attributes));
if not ((Attributes
and SFGAO_FOLDER = SFGAO_FOLDER)
and (Attributes
and SFGAO_STREAM <> SFGAO_STREAM))
then
begin
CoTaskMemFree(Result);
raise Exception.Create('
Could not convert string to PIDL');
end;
end;
function PIDLToPath(
const PIDL: PItemIDList):
string;
var
Path:
array[0..Max_Path]
of Char;
begin
if ShGetPathFromIDList(PIDL, Path)
then
Result := Path
else raise Exception.Create('
Could not convert PIDL to string');
end;
procedure TfrmMain.FormCreate(Sender: TObject);
var
s:
string;
PIDL: PItemIDList;
begin
s := '
c:\uSERs\PUBlic\DeskTop';
PIDL := PathToPIDL(s);
s := PIDLToPath(PIDL);
Memo1.Lines.Add(S);
end;