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: cyphre:seznam:cz at: 28-Jun-2002 22:14

Hello Bo, First of all I have to say that I'm not a C guru ;-) But we(together with Pekr ;-)) were experimenting some time ago with Rebol DLL interface. We has also lot of problems caused mainly by lacking the good docs but finally we got to work rebol wrapper that is able to convert/proccess/load/save about 200 image formats!Really cool stuff. Unfortunately we couldn't get to work showing images directly from the dll to View but I've written simple intermediate library in C which will suit for that purposes... I think in your case you need to pass the hprinter value as a pointer to rebol integer!. You could try following method:
>> hprinter: make integer! 0 ;this create an integer value in Rebol
== 0
>> hpr_str: make struct! [i [integer!]] reduce [hprinter] ;this is a
structure containing the Hprinter value
>> probe third hpr_str ;this give us the value(data) of hprinter
#{00000000} == #{00000000} But you probably don't need the data but pointer to this data, therefore we make another structure which will point to the structure above....
>> phpr_str: make struct! compose/deep [pi [struct! [(first hpr_str)]]] none
;this create the struct
>> probe third phpr_str ;now you can see the real pointer in memory to the
hprinter! #{703CD900} == #{703CD900} to get the data for testing if enything was changed we can made a reference value in rebol: hpr-ref: third phpr_str/pi now you can put all it into the routine: gdi32: load/library %winspool.drv openprinter: make routine! compose/deep [ "Open Printer" pprintername [string!] phprinter [struct! [(first phpr_str)]] pdefault [integer!] return: [integer!] ] gdi32 "OpenPrinterA" ret: openprinter "Brother MFC3100C" phpr_str 0 Unfortunately it doesnot work here under WIN XP. I was trying to get working at least your example but it also returned 0 under so I cannot test it further. Try to experiment with it under WIN98, maybe you will be more succesfull. Another thing is that I can be absoultely wrong ;-) Good luck! Best regards, Cyphre APPENDIX: Here is explanation of argument of the OpenPrinter routine I found in my WINAPI reference doc: pPrinterName The name of the printer or print server to obtain a handle to. If this is an empty string, the function obtains a handle to the default print server. phPrinter Receives a handle to the newly opened printer. pDefault A printer defaults structure specifying some options for opening the printer. To use the default settings, pass zero for this parameter. ----- Original Message ----- From: "Bohdan or Rosemary Lechnowsky" <[amicom--sonic--net]> To: <[rebol-list--rebol--com]> Sent: Friday, June 28, 2002 7:33 PM Subject: [REBOL] Re: View/Pro and accessing Windows Printer API (gdi32.dll)
> 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
> ;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 > st_7oz7.asp