How to Add a Network Printer Connection

Last reviewed: August 7, 1996
Article ID: Q147202
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) for:

        - Windows NT version 3.51
        - Windows 95
    

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

  • 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 reference words: kbinf 4.00
    KBCategory: kbgraphic kbhowto kbcode
    KBSubcategory: GdiPrnDrvrs


    THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

    Last reviewed: August 7, 1996
    © 1998 Microsoft Corporation. All rights reserved. Terms of Use.