・usesに ShlObj, ActiveX, ComObj を追加
//======================================================================
// 機能:デスクトップフォルダーのパス名を取得
//======================================================================
function GetWindowsDeskTopPath: string;
const
nFolder = CSIDL_DESKTOP; {デスクトップ}
var
Directory : array[0..MAX_PATH] of Char;
UnknownObject: IUnknown;
psl: IShellLink;
ppf: IPersistFile;
lpi: PItemIDList;
ppmem: IMalloc;
begin
Result := '取得エラー';
UnknownObject := CreateComObject(CLSID_ShellLink);
if not Assigned(UnknownObject) then Exit;
psl:= UnknownObject as IShellLink;
ppf:= UnknownObject as IPersistFile;
if not Assigned(psl) or not Assigned(ppf) then Exit;
if FAILED(ShGetMalloc(ppmem)) then Exit;
if FAILED(SHGetSpecialFolderLocation(0, nFolder, lpi)) then Exit;
if not SHGetPathFromIDList(lpi, Directory) then begin
if Assigned(lpi) then ppmem.Free(lpi);
Exit;
end;
Result := Directory;
end;
|
|
・インターネット上の情報や書籍の内容を一部参考に作成してます。 ・コーディング内容は著作権フリーですが、使用する場合は自己責任にてお願いします。 ・記述内容に問題点や改善点がありましたらこちらまでお願いします。 |