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: amicom:sonic at: 28-Jun-2002 10:33

OK, %winspool.drv is the correct library to use. Thanks! But now I have other problems. Hopefully some of you familiar with C and the library component of View/Pro will be able to help. Continuing from what I had in my original message (contained below):
>> openprinter: make routine! ["Open Printer" pprintername [string!]
phprinter [char*] pdefault [string!] return: [integer!]] winspool "OpenPrinterA"
>> hprinter: copy ""
== "" ;hprinter is the handle that should be returned by 'openprinter above if I understand how 'openprinter works.
>> ret: openprinter "Brother MFC3100C" hprinter ""
== 1 ;Great! 'openprinter returned 1 which indicates it worked!
>> hprinter
== "" ;Shouldn't 'hprinter now have some value that indicates the pointer? I've also tried specifying 'phprinter above as LONG, but that didn't do it either ;Let's retrieve Windows' error code to see if there was an error
>> kernel32: load/library %kernel32.dll >> getlasterror: make routine! [return: [long]] kernel32 "GetLastError" >> ret: openprinter "Brother MFC3100C" hprinter ""
== 1
>> a: getlasterror
== 0 ;OK! 'getlasterror states that there wasn't an error
>> hprinter
== "" ;but hprinter still is unchanged. Maybe my printer definition is wrong. Let's try using an invalid name (missing the last C):
>> ret: openprinter "Brother MFC3100" hprinter ""
== 0
>> ret: openprinter "Brother MFC3100C" hprinter ""
== 1 ;Well, I guess the second name IS valid according to 'openprinter. Maybe that's not the issue...let's continue with the next routine.
>> startdocprinter: make routine! ["StartDocPrinter" hprinter [char*]
dwlevel [int] lpbdocinfo [struct! [cbsize [int] lpszdocn ame [string!] lpszoutput [string!] lpszdatatype [string!] fwtype [int]]] return: [int]] winspool "StartDocPrinterA"
>> dwjob: startdocprinter hprinter 1 docinfo
== 0 ;Oh-oh! 'startdocprinter returned 0 which means it didn't work. Let's find out why:
>> getlasterror
== 6 ;This means the handle is invalid according to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/errlist_7oz7.asp ;I'm thinking maybe passing 'hprinter as an argument to 'openprinter isn't equivalent to passing &hprinter in C. Maybe we need to pass :hprinter instead. Let's try this:
>> ret: openprinter "Brother MFC3100C" :hprinter ""
== 1
>> hprinter
== ""
>> dwjob: startdocprinter :hprinter 1 docinfo
== 0
>> getlasterror
== 6 ;Same result. I've also tried replacing phprinter with a REBOL struct!, but this crashed REBOL. I'm stumped. Any ideas? At 08:26 PM 6/27/02 +0200, you wrote: