GetPrinterDriverDirectory ()

From ISXKB

Jump to: navigation, search

This article shows how to use the Windows API function GetPrinterDriverDirectory with Inno Setup.

Declaration

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

function GetPrinterDriverDirectory(
  pName: PChar;
  pEnvironment: PChar;
  Level: LongInt;
  pDriverDirectory: PChar;
  cbBuf: LongInt;
  var pcbNeened: LongInt) : Integer;
external 'GetPrinterDriverDirectoryA@winspool.drv';

GetPrinterDriverDirectory () at MSDN

Example

[Setup]
AppName=GetPrinterDriver
AppVerName=GetPrinterDriver
Uninstallable=false
DisableDirPage=true
DisableProgramGroupPage=true
DisableStartupPrompt=true
CreateAppDir=false

[Code]
function GetPrinterDriverDirectory(
  pName: PChar;
  pEnvironment: PChar;
  Level: LongInt;
  pDriverDirectory: PChar;
  cbBuf: LongInt;
  var pcbNeened: LongInt) : Integer;
external 'GetPrinterDriverDirectoryA@winspool.drv';

function GetLastError() : Integer; external 'GetLastError@kernel32.dll';

function InitializeSetup(): Boolean;
  var
     sb       : LongInt;
     PrDrvDir : String;
     err      : Integer;
begin
  // Get buffer length
  err := GetPrinterDriverDirectory ('', '', 1, '', 0, sb);
  PrDrvDir := StringOfChar (' ', sb+1);
  err := GetPrinterDriverDirectory ('', '', 1, PrDrvDir, sb, sb);
  SetLength(PrDrvDir, Pos(#0, PrDrvDir));
  MsgBox ('Printer Driver Files are in ' + PrDrvDir + '.', mbInformation, MB_OK);
  Result := false;
end;
Personal tools
Ads: