Hi,
I have an application that uses NI Reports. When I attempt to print the
report using some printers I get an error but with other printers there
is no problem at all. The printers tried are;
1. Brother MFC 9760 USB, network. OK.
2. Brother MFC 9760 USB, local. OK.
3. Epson Stylus Centronics, network. FAILS.
4. Epson Stylus Centronics, local. FAILS.
5. Cannon BJ-10EX, Centronics, network. FAILS.
6. Cannon BJ-10EX, Centronics, local. FAILS.
7. Win2PDF (a virtual PDF printer), local. OK.
The print function "NIReport_Print ()" returns -4 in all cases of
failure. Unfortunately the error messages "Misc/unknown error calling
method" & "Unknown automation error" don't mean a lot to me.
I am using CVI 6.0.0 and Windows XP Home SP1 with 496Mbytes RAM.
The printer is selected by the user from a ring control. The ring
control is populated at run time by the following function;
/* Populate the printer ring control. */
int findPrinters(void)
{
/* Variables. */
char **allPrinters;
char **printer;
char *defaultPrinter;
int numberOfPrinters = 0;
int defaultPrinterNumber;
ClearListCtrl (reportHandle, REPORT_PRINTERS);
SetCtrlVal(reportHandle,REPORT_COPIES,1);
if(0 != NIReport_GetPrinters (&defaultPrinter, &allPrinters)){
MessagePopup(title,"ERROR - unable to find printers.");
return -1;
}
printer = allPrinters;
while (*printer != NULL){
InsertListItem (reportHandle, REPORT_PRINTERS, -1,
*printer, *printer);
if(0 == strcmp(*printer,defaultPrinter))
defaultPrinterNumber = numberOfPrinters;
++numberOfPrinters;
NIReport_FreeMemory (*printer++);
}
NIReport_FreeMemory (allPrinters);
if(0 < numberOfPrinters)
SetCtrlIndex (reportHandle, REPORT_PRINTERS,
defaultPrinterNumber);
return numberOfPrinters;
}
The code to print the report is as follows;
/* Get the printer name and the number of copies required. */
GetCtrlIndex (reportHandle, REPORT_PRINTERS, &index);
GetValueLengthFromIndex (reportHandle, REPORT_PRINTERS,
index, &length);
if(500 < length){
MessagePopup(title,"ERROR - printer name too long.");
return;
}
GetCtrlVal(reportHandle,REPORT_PRINTERS,printerName);
GetCtrlVal(reportHandle,REPORT_COPIES,&copies);
/* Print the report.*/
if(0 != (status=NIReport_Print (niReportHandle, printerName,
copies))){
sprintf(msgStr,"Error %d; %s occured when printing the
report to %s.",status,NIReport_GetErrorString (status),printerName);
MessagePopup(title,msgStr);
}
else{
MessagePopup(title,"Report printed.");
}
If you can help at all I'd be very grateful.
--
John Cameron