ERangeError in SRVPrint.GetPrinterInfo when default printer's CreateDC fails (division by zero PixPerInch)

General TRichView support forum. Please post your questions here
Post Reply
apfau
Posts: 1
Joined: Thu Aug 08, 2024 10:57 am

ERangeError in SRVPrint.GetPrinterInfo when default printer's CreateDC fails (division by zero PixPerInch)

Post by apfau »

We hit an ERangeError in SRVPrint.GetPrinterInfo (SRVPrint.pas line 260) at form-load time, triggered via TSRVPrint.Loaded → UpdatePage → calculateSize → calculatePictureSize → GetPrinterInfo.

Root cause: on a machine where the default printer's CreateDC fails (offline/redirected printer, stopped spooler, broken driver), RV_GetPrinterDC returns a NULL HDC but the result is never checked. Every subsequent GetDeviceCaps then returns 0, so PixPerInchX/Y = 0, and line 260 computes round(0 / 0 * 25.4). With FPU exceptions masked, that yields Int64.MinValue, which overflows the Integer assignment under range checking.

Could you guard GetPrinterInfo against an invalid DC — e.g. if RV_GetPrinterDC returns 0 (or PixPerInchX/Y come back 0), fall back to the same defaults used in the "no printer" branch instead of dividing by them?
Post Reply