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