How to Add a Network Printer Connection

ID: Q147202


The information in this article applies to:


SUMMARY

When writing a Win32 application that installs a network printer connection, you must take into consideration differences in printing if the application will be run under both Windows 95 and Windows NT. One important difference is that Windows NT may download appropriate drivers from the print server while under Windows 95, you need to add the printer driver files to the system with the AddPrinterDriver() function.


MORE INFORMATION

This process should take two separate code paths depending on whether you are running Windows NT or Windows 95. In Windows 95, you will want to add the printer driver with AddPrinterDriver() and add the printer connection with AddPrinter(). In Windows NT, you need only call the AddPrinterConnection() function.

Steps for Adding a Printer Connection in Windows 95


  1. Fill out a DRIVER_INFO_2 structure with the appropriate driver information for the network printer.


  2. Copy the driver files to your Windows 95 System directory.


  3. Call AddPrinterDriver() to add the printer driver to Windows 95.


  4. Fill out a PRINTER_INFO_2 structure, and place a pointer to the server and share name in the pPortName field.


  5. Call AddPrinter() to add the printer to the system.


Here is an example of how you might do this (assuming you have copied the driver files to the Windows 95 System directory):


   PRINTER_INFO_2 pi2;
   DRIVER_INFO_2 di2;
   HANDLE hPrinter;

   ZeroMemory(&di2, sizeof(DRIVER_INFO_2));
   di2.cVersion = 1024;
   di2.pName = "HP Laserjet 4Si";
   di2.pEnvironment = "Windows 4.0";
   di2.pDriverPath = "c:\\windows\\system\\hppcl5ms.drv";
   di2.pDataFile   = "c:\\windows\\system\\hppcl5ms.drv";
   di2.pConfigFile = "c:\\windows\\system\\hppcl5ms.drv";
   AddPrinterDriver(NULL, 2, (LPBYTE)&di2);

   ZeroMemory(&pi2, sizeof(PRINTER_INFO_2));
   pi2.pPrinterName = "HP Laserjet 4Si";
   pi2.pPortName = "\\\\server\\print_share";
   pi2.pDriverName = "HP Laserjet 4Si";
   pi2.pPrintProcessor = "WinPrint";
   pi2.pDatatype = "EMF";
   hPrinter = AddPrinter(NULL, 2, (LPBYTE)&pi2);
   ClosePrinter(hPrinter); 

  1. Make sure you close the printer handle returned from AddPrinter, by using the ClosePrinter API.


You can add a printer connection under Windows NT by making this call:


   AddPrinterConnection ("\\\\server\\print_share"); 

Additional query words: kbinf 4.00 KBINF GDI WINDOWS 95 GRAPHICS PRINTING


Keywords          : kbcode GdiPrnDrvrs 
Version           : 4.00 | 3.51
Platform          : NT WINDOWS 
Issue type        : 

Last Reviewed: March 6, 1999