LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

SetPrintAttribute (ATTR_PRINTER_NAME, printer name) fails

I am using the commands:

setprinterstat=SetPrintAttribute (ATTR_PRINTER_NAME, "\\\nt1emr\\SAVIN 2545");
PrintMCSPanelStatus=PrintPanel (mcsSheet, NULL, 1, VAL_FULL_PANEL, 0);

to print to another printer than the default printer of my computer.

When I execute them, the print job goes directly to the default printer as if "\\\nt1emr\\SAVIN 2545" was NULL!!
This printer exists and is on the network. I can print to it from my computer.

Please advise,
Loubna
0 Kudos
Message 1 of 6
(4,078 Views)
You need to double-slash all backslashes. So if you need two in your end result, use four in your string constant. You missed an opening backslash. Try the following:
SetPrintAttribute (ATTR_PRINTER_NAME, "\\\\nt1emr\\SAVIN 2545");
0 Kudos
Message 2 of 6
(4,071 Views)
I did like you said but it didn't work.
The page is still sent to the default printer!!
0 Kudos
Message 3 of 6
(4,067 Views)
I don't know if CVI PrintPanel has a problem with a printer name with a space in it. Do you have another network printer you can try without a space in the name?
0 Kudos
Message 4 of 6
(4,061 Views)
I thought about that as well and tried using another printer without spaces but it still failed and printed to default.
It is as if the command for changing the printer name was ignored.
Here are all the commands I used:
SetPrintAttribute (ATTR_ORIENTATION, VAL_PORTRAIT);
SetPrintAttribute (ATTR_PRINT_AREA_HEIGHT, VAL_USE_ENTIRE_PAPER);
SetPrintAttribute (ATTR_PRINT_AREA_WIDTH, VAL_USE_ENTIRE_PAPER);
SetPrintAttribute (ATTR_BITMAP_PRINTING, 1);
SetPrintAttribute (ATTR_NUMCOPIES, 2);
SetPrintAttribute (ATTR_PRINTER_NAME, "\\\\nt1emr\\oilfield");

they all succeeded except the last one!!
0 Kudos
Message 5 of 6
(4,059 Views)
In CVI 6.0 running under Windows 2000, I've had very little success getting PrintPanel to select a different printer.

I set PrintPanel to show the Confirm Dialog Box:
prnErr = PrintPanel (panelHandle, "", 1, VAL_VISIBLE_AREA, 1);
The Print dialog box that then pops up shows the printer that PrintPanel will be using.

As you said in your last message, it seems like PrintPanel ignores SetPrintAttribute (ATTR_PRINTER_NAME, "anyprinter").

It also doesn't seem to recognize a change in the default printer. I changed default printers from Start >> Settings >> Printers. PrintPanel didn't see the change. I used the SDK function SetDefaultPrinter. PrintPanel didn't see the change. (I used the Start menu to verify that the default had been changed).

PrintPanel seems to go off the PrinterPorts list in the registry. Whatever printer is on top of the list is used by PrintPanel, regardless of which printer is the default. My default printer was on top of the list. I went to Start >> Settings >> Printers and deleted the printer which was my default. PrintPanel then used the printer now on top of the PrinterPorts list, even though that printer was not the default.

Then I found this Microsoft Knowledgebase article about removing a network printer.
http://support.microsoft.com/kb/q188697/
After I deleted the registry keys, I was able to use SetDefaultPrinter and PrintPanel to select two of the six printers I had installed, but not all of them.

Anyway, you can try something like this:

Add ...\CVI\SDK\lib\WinSpool.lib to your project

#include < windows.h > // delete spaces around windows.h
#include < winspool.h > // delete spaces around winspool.h
//...
DWORD size = MAX_PATHNAME_LEN;
char prevDefaultPrn[MAX_PATHNAME_LEN];
int prnErr;

//...
GetDefaultPrinter((LPSTR) prevDefaultPrn, &size);
// set the default to the new printer
SetDefaultPrinter((LPSTR) "\\\\nt1emr\\oilfield");
prnErr = PrintPanel (panelHandle, "", 1, VAL_VISIBLE_AREA, 1);
// restore the previous default printer
SetDefaultPrinter((LPSTR) prevDefaultPrn);
0 Kudos
Message 6 of 6
(4,049 Views)