LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Labview 6 to call OpenPrinter()

I would like to use Labview 6.0.2 to call API winspool.drv function OpenPrinter().
0 Kudos
Message 1 of 5
(3,295 Views)
From the palette Advanced select "Call Library Function". From the context menu use Configure.... In the dialog type winspool.drv into the "Library Nome or Path" field. Now you can select the function. Be aware that you must use the OpenPrinterA function because LV 6 is not Unicode enabled.
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 2 of 5
(3,285 Views)
Thanks for your help, but I had already tried the steps you suggested. The OpenPrinter() function takes two input parameters: one is the printer name, the other parameter the printer defaults with its type of data as structure in C, which is equivelent to  the data type of cluster in Labview. The only output parameter from this function shall return a handle of the printer, but when I used the labview node to call this function, the output variable returns zero, which means the function call is not working. I suspected the cause is probably due to that I did not correctly pass the second input parameter to the function. I will really appreciate if you could take time to try to run your code to see if you could get it to work.
0 Kudos
Message 3 of 5
(3,270 Views)
I'm sorry I haven't any information about the OpenPrinter function itself here. Next week I have the chance to look into the MSDN to get the information.
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 4 of 5
(3,267 Views)


jzhang@sjm.com wrote:
Thanks for your help, but I had already tried the steps you suggested. The OpenPrinter() function takes two input parameters: one is the printer name, the other parameter the printer defaults with its type of data as structure in C, which is equivelent to  the data type of cluster in Labview. The only output parameter from this function shall return a handle of the printer, but when I used the labview node to call this function, the output variable returns zero, which means the function call is not working. I suspected the cause is probably due to that I did not correctly pass the second input parameter to the function. I will really appreciate if you could take time to try to run your code to see if you could get it to work.

This is not trivial.

The function prototype is
BOOL WINAPI OpenPrinterA(LPSTR lpPrinterName,HANDLE *phPrinter, LPPRINTER_DEFAULTSA pDefault);

The second parameter would be no problem you just treat it as a pointer to an uInt32 but the third is a pain. Its structure definition is:

typedef struct _PRINTER_DEFAULTSA {
  LPSTR        pDatatype;
  LPDEVMODEA pDevMode;
  ACCESS_MASK  DesiredAccess;
} PRINTER_DEFAULTSA, *LPPRINTER_DEFAULTSA;

with all but the ACCESS_MASK parameter being a pointer to some memory. You could pass in a NULL for this parameter in which case certain defaults will be assumed and you could theoretically change them later on by calling SetJob().

But here comes the crux of this: Using the returned printer handle for anything (with or without having specified a valid defaults structure) will require you to call many more Windows API functions, and some of them are even more complex than this one. All in all if you really need to do something by opening the Printer Driver in winspool.drv, it is a much better idea to implement that in an external DLL written in C with a LabVIEW friendly  calling interface and import that into your LabVIEW application instead.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 5 of 5
(3,252 Views)