Hi, the new code as below:
//----Code begin----
var
_Kernel32Handle: HMODULE = HMODULE(0);
_GetLongPathName: function (lpszShortPath: PAnsiChar; lpszLongPath: PAnsiChar;
cchBuffer: DWORD): DWORD; stdcall;
function Kernel32Handle: HMODULE;
begin
if _Kernel32Handle = HMODULE(0) then
_Kernel32Handle := LoadLibrary(kernel32);
Result := _Kernel32Handle;
end;
function ShellGetLongPathName(const Path: string): string;
var
PIDL: PItemIDList;
Desktop: IShellFolder;
AnsiName: string;
WideName: array [0..MAX_PATH] of WideChar;
Eaten, Attr: ULONG;
begin
Result := Path;
if Path <> '' then
begin
if Succeeded(SHGetDesktopFolder(Desktop)) then
begin
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, PChar(Path), -1, WideName, MAX_PATH);
if Succeeded(Desktop.ParseDisplayName(0, nil, WideName, Eaten, PIDL, Attr)) then
try
SetLength(AnsiName, MAX_PATH);
if SHGetPathFromIDList(PIDL, PChar(AnsiName)) then
StrResetLength(AnsiName);
Result := AnsiName;
finally
CoTaskMemFree(PIDL);
end;
end;
end;
end;
function ShortNameToLongName(const FileName: string): string;
begin
Result := FileName;
if not Assigned(_GetLongPathName) then
_GetLongPathName := GetProcAddress(Kernel32Handle, 'GetLongPathNameA');
if Assigned(_GetLongPathName) then
begin
SetLength(Result, MAX_PATH);
SetLength(Result, _GetLongPathName(PChar(FileName), PChar(Result), MAX_PATH));
end
else
begin
Result := ShellGetLongPathName(FileName);
end;
end;
//---- Code End ----
I haven't test it, could you test it?
If the code is OK, I will commit it.
|