ERangeError in SRVPrint.GetPrinterInfo when default printer's CreateDC fails (division by zero PixPerInch)
Posted: Tue Jun 16, 2026 6:46 am
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?
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?