Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: View/Pro and accessing Windows Printer API (gdi32.dll)

From: greggirwin:mindspring at: 1-Jul-2002 20:44

Hi Bo, << If anyone has suggestions on why StartDocPrinter doesn't like the handle, I'd be very curious to find out! >> Below is a modified version of your script. Let me know if it works OK for you (I'm on W2K and some structures have changed compared to '95). If you have any questions about the changes I made, just holler. Hopefully I didn't muddy things up too badly. --Gregg REBOL [] winspool: load/library %winspool.drv kernel32: load/library %kernel32.dll print "Define GetLastError" getlasterror: make routine! [ return: [long] ] kernel32 "GetLastError" print "Define OpenPrinter" openprinter: make routine! [ "Open Printer" pprintername [string!] phprinter [char*] pdefault [integer!] ;[string!] We want to pass a NULL here for now. return: [integer!] ] winspool "OpenPrinterA" ; Added ClosePrinter so we can clean up while testing. Gregg print "Define ClosePrinter" closeprinter: make routine! [ "Close Printer" hprinter [integer!] return: [integer!] ] winspool "ClosePrinter" ; DOCINFO is used by StartDoc, and has a different structure than StartDocument, ; which the spooler uses. StartDoc is what you use for the actual printing ; commands (to a device context). The spooler uses the DOC_INFO_1 structure ; which doesn't have the size or type elements. print "Define StartDocPrinter" startdocprinter: make routine! [ "StartDocPrinter" hprinter [integer!] ;[char*] This needs to be an integer here. dwlevel [integer!] ;[int] lpbdocinfo [ struct! [ ;cbsize [int] lpszdocname [string!] lpszoutput [string!] lpszdatatype [string!] ;fwtype [int] ] ] return: [integer!] ] winspool "StartDocPrinterA" print {Create a Null Buffer - Thanks to Gregg Irwin and Gabrielle Santilli on REBOL list} null-buff: func [len][ head insert/dup make string! len #"^(00)" len ] print {Create Pointer Variable - Thanks again to Gregg Irwin} prin "Initial value: " probe to-binary hprinter: null-buff 4 ; You have to give it a datatype it understands (e.g. "RAW"), ; rather than an empty string. print "Create DocInfo Struct" docinfo: make struct! [ ;cbsize [int] lpszdocname [string!] lpszoutput [string!] lpszdatatype [string!] ;fwtype [int] ] reduce ["Test Print" "" "RAW"] ;[100 "Test Print" "" "" 0] ;!!! I CHANGED THE PRINTER NAME FOR TESTING !!! Gregg print "Call OpenPrinter" print either zero? ret: openprinter "HP LaserJet 4" hprinter 0 ["FAIL!"]["Success"] prin "Current value: " probe to-binary hprinter ; Have to cast the string buffer to a proper-endian integer. ; The string buffer trick is only needed for return filled (i.e. OUT) parameters. hprinter: to-integer to-binary head reverse hprinter print ["Printer handle:" hprinter] ; Don't forget, for structures that *do* have a size element, that you have to ; set it before the call. ;print "Set docinfo structure size" ;print docinfo/cbsize: length? third docinfo print "Call StartDocPrinter" print either zero? dwjob: startdocprinter hprinter 1 docinfo [["ERROR!" getlasterror]]["SUCCESS!"] print "Closing Printer" print either zero? ret: closeprinter hprinter ["FAIL!"]["Success"] halt