Steema Issues Database

Note: This database is for bugs and wishes only. For technical support help, if you are a customer please visit our online forums;
otherwise you can use StackOverflow.
Before using this bug-tracker we recommend a look at this document, Steema Bug Fixing Policy.



Bug 114 - GPF in function LongPathName
Summary: GPF in function LongPathName
Status: RESOLVED FIXED
Alias: None
Product: VCL TeeChart
Classification: Unclassified
Component: Export (show other bugs)
Version: 131016
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Steema Issue Manager
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-19 18:07 EST by John Santmann
Modified: 2013-11-29 10:07 EST (History)
1 user (show)

See Also:
Chart Series: ---
Delphi / C++ Builder RAD IDE Version:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Santmann 2013-11-19 18:07:34 EST
Problem with the following procedure which generates GPF because it needs GetLongPathNameW instead of GetLongPathNameA.
In addition, the buffer is one byte too small. 
Fix is in code below.

function LongPathName(const FileName:String):String;
var
  BufferSize: DWord;
begin
  // "GetLongPathNameA" available only for Win2000, WinXP or Win2003, or newer !
  if (Win32Platform=VER_PLATFORM_WIN32_NT) and (WindowsMajorVersion>=5) then
  begin
(* 
// --------- BEGIN REMOVED CODE -----------
    if TeeKernel32=0 then
    begin
      TeeKernel32:=TeeLoadLibrary(kernel32);

      if TeeKernel32<>0 then
         @GetLongPathName:=GetProcAddress(TeeKernel32,'GetLongPathNameA');
    end;

    BufferSize := GetLongPathName(PChar(FileName), nil, 0);
    SetLength(Result, BufferSize - 1);
    GetLongPathName(PChar(FileName), PChar(Result), BufferSize);   
// ----------- END RREMOVED CODE ----------
*)

    // 2/19/2009 ------------ BEGIN CODE ADDED -----------------
    if TeeKernel32=0 then
    begin
      TeeKernel32:=TeeLoadLibrary(kernel32);

      if TeeKernel32<>0 then
         @GetLongPathName:=GetProcAddress(TeeKernel32,'GetLongPathNameW');
    end;

      // returns length (including #0) of LongPath (or 0 if not found or error)
    BufferSize := GetLongPathName(PChar(FileName),        // lpszShortPath                   
                                  PChar(Result),          // Out lpszLongPath               
                                  0) ;                    // cchBuffer                      
    SetLength(Result,                                                                         // ''
              BufferSize) ;                                                                 
    GetLongPathName(PChar(FileName),                       // lpszShortPath                  
                    PChar(Result),                         // Out lpszLongPath               
                    BufferSize) ;                          // cchBuffer                      
    If BufferSize > 0 then
    SetLength(Result,                                      // remove #0                       
              BufferSize - 1) ;                                                              
// 2/19/2009 - END FIXED CODE ADDED
  end
  else
    result:=FileName;
end;
Comment 1 david berneda 2013-11-20 04:20:17 EST
Thanks for reporting.
Can you confirm which IDE is showing the problem? (Delphi 2009 or 2010?)
Comment 2 david berneda 2013-11-29 10:07:19 EST
Fixes have been applied, but to be compatible with non-unicode Delphi versions, this line should be:

@GetLongPathName:=GetProcAddress(TeeKernel32,{$IFDEF UNICODE}'GetLongPathNameW'{$ELSE}'GetLongPathNameA'{$ENDIF});