Gregg,

Your solution does return an apparently valid handle when I apply it to 
OpenPrinter, but StartDocPrinter still doesn't like it (returns a code of 6 
which means "invalid handle").

Here's my script so far (beware of line-wrapping!):

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 [string!]
         return: [integer!]
] winspool "OpenPrinterA"

print "Define StartDocPrinter"
startdocprinter: make routine! [
         "StartDocPrinter"
         hprinter [char*]
         dwlevel [int]
         lpbdocinfo [struct! [
                 cbsize [int]
                 lpszdocname [string!]
                 lpszoutput [string!]
                 lpszdatatype [string!]
                 fwtype [int]
         ]]
         return: [int]
] 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

print "Create DocInfo Struct"
docinfo: make struct! [
         cbsize [int]
         lpszdocname [string!]
         lpszoutput [string!]
         lpszdatatype [string!]
         fwtype [int]
][100 "Test Print" "" "" 0]

print "Call OpenPrinter"
print either zero? ret: openprinter "Brother MFC3100C" hprinter "" 
["FAIL!"]["Success"]

prin "Current value: "
probe to-binary hprinter

print "Call StartDocPrinter"
print either zero? dwjob: startdocprinter hprinter 1 docinfo [["ERROR!" 
getlasterror]]["SUCCESS!"]

halt

If anyone has suggestions on why StartDocPrinter doesn't like the handle, 
I'd be very curious to find out!

Thanks for all the help so far.  I'm hoping that someday REBOL users can 
have graphical access to printers.  I know it would make my applications a 
lot more useful!

-Bo

At 09:23 AM 6/29/02 -0600, you wrote:
>Hi Bo,
>
><< ;hprinter is the handle that should be returned by 'openprinter above if
>I
>understand how 'openprinter works. >>
>
>I think you need to pass a buffer and then check that when the call returns.
>That's what I had to do to use the return connection ID from InternetDial.
>Here's the idea. I have to run right now, but I'll check back tomorrow, or
>mail me directly if this causes more confusion.
>
>     win-lib: load/library %wininet.dll
>
>     internet-dial: make routine! [
>         hwnd-parent [integer!]
>         connectoid  [string!]
>         flags       [integer!]
>         rtn-conn-id [char*]     ; LPDWORD - either string! or char* work
>here
>         reserved    [integer!]
>         return:     [integer!]
>     ] win-lib "InternetDial"
>
>     ;-- Internal support routines
>
>     null-buff: func [
>         {Returns a null-filled buffer of the specified length.}
>         len [integer!]
>     ][
>         to-string array/initial len #"^@"
>     ]
>
>
>     ;-- Interface routines
>
>     connect: func [
>         {Initiates dial-up connection. Returns connection ID (to use with
>          disconnect) if successful; false otherwise.}
>         dial-up-name [string!]
>         /local id
>     ][
>         id: null-buff 4
>         last-error: internet-dial no-hwnd dial-up-name dial-unattended id
>zero
>         either all [(last-error = 0) (id <> null-buff 4)] [
>             last-error: none
>             return to-integer to-binary head reverse id
>         ][
>             return false
>         ]
>     ]
>
>HTH!
>
>--Gregg
>
>--
>To unsubscribe from this list, please send an email to
>[EMAIL PROTECTED] with "unsubscribe" in the
>subject, without the quotes.

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to