Subject: GetLongPathNameA function PROBLEM [Print This Page] Author:
mjasinski Time: 2006-11-27 22:54 Subject: GetLongPathNameA function PROBLEM
File CnCommon.pas includes this lines (cnpack part):
function GetLongPathNameA(lpszShortPath: PAnsiChar; lpszLongPath: PAnsiChar;
cchBuffer: DWORD): DWORD; stdcall; external 'kernel32.dll'
name 'GetLongPathNameA';
The GetLongPathName API call is only available on Windows 98/ME and
Windows 2000/XP. It is not available on Windows 95 & NT.
But file JclFileUtils.cpp includes better solution (cnwizards part):
function RtdlGetLongPathName(const Path: string): string;
begin
Result := Path;
if not Assigned(_GetLongPathName) then
_GetLongPathName := GetModuleSymbol(Kernel32Handle, 'GetLongPathNameA');
if not Assigned(_GetLongPathName) then
Result := ShellGetLongPathName(Path)
else
begin
SetLength(Result, MAX_PATH);
SetLength(Result, _GetLongPathName(PChar(Path), PChar(Result), MAX_PATH));
end;
end;
I improved CnCommon.pas.
I have compiled sources and my CnWizards_CB6.dll works on WinNT correctly.
//----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.Author:
mjasinski Time: 2006-11-29 18:50
I have tested it. No error.
In my compilation some icons near the form are very fuzzy (system Windows NT).
Could You compile and send me CnWizards_CB6.dll ?
email: mja@onet.pl