GetLongPathName ()

From ISXKB

Jump to: navigation, search

This article shows how to use the Windows API function GetLongPathName with Inno Setup. The article is based on a post from Jordon Russel (http://news.jrsoftware.org/news/innosetup.code/msg09341.html).

Contents

Declaration

The following declaration is required in a [Code] section:

function GetLongPathName (lpszShortPath, lpszLongPath: String; cchBuffer: DWORD): DWORD;
 external 'GetLongPathNameA@kernel32.dll stdcall';

GetLongPathName () at MSDN

Example

function LongPath(const Path: String): String;
var
  Buf: String;
  Len: Integer;
begin
  // Initialize buffer length - 4 KB should be more than sufficient
  SetLength(Buf, 4096);

  Len := GetLongPathName(Path, Buf, Length(Buf));

  if (Len > 0) and (Len < Length(Buf)) then
  begin
    // The function was successful. Truncate the buffer to the
    // returned length.
    SetLength(Buf, Len);
    Result := Buf;
  end
  else
  begin
    // The function failed, or the resulting path couldn't fit
    // in the buffer. Just return the path we were passed.
    Result := Path;
  end;
end;

See Also

Personal tools
Ads: