JackTrapper / DelphiBugs

Bug tracker for Delphi
7 stars 2 forks source link

TPrinter.SetPrinter passes garbage rather than nil to DocumentProperties API #6

Open JackTrapper opened 5 years ago

JackTrapper commented 5 years ago

Tested

Background

When using the Windows DocumentProperties function:

LONG DocumentProperties(
  _In_  HWND     hWnd,
  _In_  HANDLE   hPrinter,
  _In_  LPTSTR   pDeviceName,
  _Out_ PDEVMODE pDevModeOutput,
  _In_  PDEVMODE pDevModeInput,
  _In_  DWORD    fMode
);

The 2nd-last pDevModeInput argument is optional:

pDevModeInput [in]

A pointer to a DEVMODE structure that the operating system uses to initialize the property sheet controls.

This parameter is only used if the DM_IN_BUFFER flag is set in the fMode parameter. If DM_IN_BUFFER is not set, the operating system uses the printer's default DEVMODE.

TPrinter.SetPrinter passes uninitialized junk as this 2nd optional parameter rather than nil:

if DocumentProperties(0, FPrinterHandle, ADevice, DevMode^, DevMode^, DM_OUT_BUFFER) < 0 then