How To Add a Network Printer Connection

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");
Lastnosti

ID članka: 147202 – Zadnji pregled: 11. jul. 2005 – Revizija: 1

Povratne informacije