This script uses OLE and DLL to identify the default printer.
' identify the Default Printer
' The called functional specification:
' BOOL GetDefaultPrinter( _In_ LPTSTR pszBuffer, _Inout_ LPDWORD pcchBuffer )
' we need to pass it the address of a character string (the buffer) , and the address where the buffer length is held
' Create the buffer as a WORDARRAY, WORD since we are using the Widecharacter version of GetDefaultPrinter
' Note how the address of the user data are passed to the call using @
' Also note how we use cstr to convert the filled in WORDARRAY (buffer) to displayable text-
dim myDLL = dll.open ("winspool.drv")
if ( myDLL == 0 ) THEN
Message ="Could not open the DLL file"
dim defPrn = dll.link( myDLL, "GetDefaultPrinterW",2,"unsigned" )
if (! defPrn ) THEN ' Sorry, do NOT use IF ( defPrn = 0) THEN
Message ="Could not find the named procedure"
dim strlen = 255
dim str = WORDARRAY ( strlen + 1 )
if ( defPrn ( @ str , @ strlen ) ) then
freestring = "Default printer: " & cstr ( str)
freestring = "GetDefaultPrinter failed"
message = freestring