See also:
DO declare
LOCAL cCurrentPrinter
cCurrentPrinter = GetDefaultPrinter()
? "Default printer:", cCurrentPrinter
IF SetDefaultPrinter("Microsoft XPS Document Writer") = 0
* 1801 - ERROR_INVALID_PRINTER_NAME
? "SetDefaultPrinter failed:", GetLastError()
ELSE
? "New default printer:", GetDefaultPrinter()
SetDefaultPrinter(m.cCurrentPrinter)
? "Default printer restored:", GetDefaultPrinter()
ENDIF
* end of main
FUNCTION GetDefaultPrinter
LOCAL cPrinter, nBufsize, nResult
nBufsize = 250
cPrinter = REPLICATE(CHR(0), nBufsize)
TRY
IF GetDefaultPrinterAPI(@cPrinter, @nBufsize) <> 0
cPrinter = SUBSTR(cPrinter, 1,;
AT(Chr(0),cPrinter)-1)
ELSE
cPrinter=""
ENDIF
CATCH
cPrinter=""
ENDTRY
RETURN m.cPrinter
PROCEDURE declare
DECLARE INTEGER GetLastError IN kernel32
DECLARE INTEGER SetDefaultPrinter IN winspool.drv;
STRING pszPrinter
DECLARE INTEGER GetDefaultPrinter IN winspool.drv;
as GetDefaultPrinterAPI;
STRING @pszBuffer,;
INTEGER @pcchBuffer