CnPack Forum


 
Subject: GetLongPathNameA function PROBLEM
mjasinski
新警察
Rank: 1



UID 3423
Digest Posts 0
Credits 3
Posts 3
点点分 3
Reading Access 10
Registered 2006-11-27
Status Offline
Post at 2006-11-27 22:54  Profile | Blog | P.M. 
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.

Could You apply this trick in CnCommon.pas file?

Mariusz Jasinski
Poland
Top
shenloqi
灌水处处长
Rank: 4



UID 34
Digest Posts 1
Credits 287
Posts 179
点点分 287
Reading Access 10
Registered 2003-3-15
Status Offline
Post at 2006-11-29 10:07  Profile | P.M. 
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.
Top
mjasinski
新警察
Rank: 1



UID 3423
Digest Posts 0
Credits 3
Posts 3
点点分 3
Reading Access 10
Registered 2006-11-27
Status Offline
Post at 2006-11-29 18:50  Profile | Blog | P.M. 
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

Mariusz Jasinski


Image Attachment: fuzzy_icons_2.gif (2006-11-29 18:50, 8.83 K)



Image Attachment: fuzzy_icons.gif (2006-11-29 18:50, 10.58 K)

Top
shenloqi
灌水处处长
Rank: 4



UID 34
Digest Posts 1
Credits 287
Posts 179
点点分 287
Reading Access 10
Registered 2003-3-15
Status Offline
Post at 2006-11-29 20:34  Profile | P.M. 
I updated CnCommon.pas in CVS.

These icons looks ugly may because your operating system is WinNT, which not support 256 bit color icons.

I can not compile CnWizards_CB6.dll because I have no BCB, I am sorry for that.
Top
mjasinski
新警察
Rank: 1



UID 3423
Digest Posts 0
Credits 3
Posts 3
点点分 3
Reading Access 10
Registered 2006-11-27
Status Offline
Post at 2006-11-30 16:18  Profile | Blog | P.M. 
Ok, thanks.
I will must change OS :-)
Top
shenloqi
灌水处处长
Rank: 4



UID 34
Digest Posts 1
Credits 287
Posts 179
点点分 287
Reading Access 10
Registered 2003-3-15
Status Offline
Post at 2006-11-30 22:27  Profile | P.M. 
You're welcome
Top
 




All times are GMT++8, the time now is 2024-11-22 01:02

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.008415 second(s), 8 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP