LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

NIReport_GetPrinters doesn't return all printer names

Hello,
NIReport_GetPrinters doesn't return all the printer names installed in my system. The source code below only returns printer Fax (see attached screen dump from my printers) in variable allPrinters. Default printer in variable defaultPrinter is returned correctly. My goal is to seek the CutePDF printer and write to that printer in any case.
I'm using W2K Professional (Swedish). First three printers installed in the system are local, rest three network printers.
Regards,
Petri
 
#include "nireport.h"

int main (int argc, char *argv[])
{
 char **allPrinters=NULL;
 char *defaultPrinter=NULL;
 char **printer=NULL;
 
 NIReport_GetPrinters (&defaultPrinter, &allPrinters);
 printer = allPrinters;
 while (*printer != NULL)
  NIReport_FreeMemory (*printer++);
 NIReport_FreeMemory (allPrinters);
 
 return 0;
}
 
0 Kudos
Message 1 of 3
(3,025 Views)
Hello Petri,
 
I think the issue lies with how you are viewing your information and the fact that you're initializing your values to NULL.  According to the All Printer parameter of the NIReports_GetPrinters function, if you pass NULL to this parameter, it indicates that you do not need this information.
 
Also, in the documentation for this parameter, it shows a helpful example, I have modifed it and posted it below.  You should add a watch statement for the printer variable, and notice that everytime you hit the breakpoint set on NIReport_FreeMemory, the value of printer will be set to the name of one of your printers.  In other words, you should hit the breakpoint seven times (1 for each printer on your system, and 1 for the NULL at the end of the list).
 
void GetAndFreePrinters (void)
{
   char **allPrinters;
   char **printer;

   NIReport_GetPrinters (NULL, &allPrinters);
   printer = allPrinters;
   while (*printer != NULL)
      // you should put a breakpoint on the line below so you can see what value is stored
      // in printer before it is freed
      NIReport_FreeMemory (*printer++);    
   NIReport_FreeMemory (allPrinters);
}
 
Hope that helps.
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 2 of 3
(2,998 Views)
thanks, it works now.
Regards,
Petri
0 Kudos
Message 3 of 3
(2,976 Views)