Using the LEADTOOLS Virtual Printer as an Internet Printing Protocol (IPP) Printer

Take the following steps to create and run a program that uses the LEADTOOLS Network Virtual Printer Driver as an IPP printer:

  1. Start Visual Studio 2008.

  2. From the main menu, choose File->New->Project...

  3. In the New Project dialog box, choose Visual C++ in the Project Types drop-down list box, and choose MFC Application in the Templates.

  4. Type the project name as “LEADTOOLS IPP Demo” in the Project Name field.

  5. In the Location field, use the Browse button to navigate to the Examples subdirectory (such as <LEADTOOLS_INSTALLDIR>\Examples\VirtualPrinter\CDLL). Clear the Create Directory For Solution and Add to Source Control check boxes. Click OK.

  6. Click Next> in the MFC Application Wizard.

  7. Select dialog based application type. Then click Finish. Three folders will be created, entitled: "Header Files", "Resource Files", and "Source Files".

  8. From the Main menu, choose Project->Properties.

  9. In the Properties dialog box, choose Configuration Properties, then select C/C++, then select Preprocessor.

  10. On the right side set the Preprocessor Definitions Property to use LTVXX_CONFIG, then click OK.

  11. In Solution Explorer, open stdafx.h, and add the following code to the end of the file:

    #include "winspool.h"   
    #include "..\..\..\Include\Ltprinter.h"   

  12. In the Source Files, right -click the folder. Choose Add->New Item. Choose Code in Categories, and C++ File (.cpp) in Templates. Type Imports in the name field and click Add.

  13. Right-click Imports.cpp and click Open. Add the following code:

    #include "stdafx.h" 
    #if defined(WIN64) 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR\\CDLL\\x64\\Ltkrn_x.lib) 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR\\CDLL\\x64\\Ltprinter_x.lib) 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR\\CDLL\\x64\\LtDocWrt_x.lib) 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR\\CDLL\\x64\\Ltfil_x.lib) 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR\\CDLL\\x64\\Ltdis_x.lib) 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR\\CDLL\\Win32\\Ltkrn_u.lib) 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR\\CDLL\\win32\\Ltprinter_u.lib) 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR\\CDLL\\win32\\LtDocWrt_u.lib) 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR\\CDLL\\win32\\Ltfil_u.lib) 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR\\CDLL\\win32\\Ltdis_u.lib) 
    #endif  // #if defined(WIN64) 

  14. Right-click LEADTOOLS IPP DemoDlg.h and click Open. Add the following function definitions to the CLEADTOOLSIPPDemoDlg class:

    afx_msg void OnBnClickedOk(); 
    static L_INT (EXT_CALLBACK OnEmfRgsProc)( L_WCHAR*, HGLOBAL, L_UINT, L_VOID* ); 
    static L_INT (EXT_CALLBACK OnJobInfoProc)( L_WCHAR*, DWORD, DWORD, L_VOID* ); 
    L_L_INT EnableInternetPrinting(); 
    L_VOID RegisterJobCallBack(); 
    L_VOID RegisterEmfCallBack(); 
    L_INT InstallPrinter(); 
    BOOL SharePrinter(LPTSTR szPrinterName, LPTSTR szShareName, BOOL bShare); 

  15. Right-click LEADTOOLS IPP DemoDlg.cpp and click Open. Add the following function:

    //Locate BEGIN_MESSAGE_MAP(CLEADTOOLSIPPDemoDlg, CDialog) and add the following functions 
    //Add the following function implementations 
    void CLEADTOOLSIPPDemoDlg::OnBnClickedOk() 
    L_INT CLEADTOOLSIPPDemoDlg::InstallPrinter() 
       PRNPRINTERINFO docPrinterInfo; 
       memset(&docPrinterInfo, 0, sizeof(PRNPRINTERINFO)); 
       docPrinterInfo.uStructSize = sizeof(PRNPRINTERINFO); 
       docPrinterInfo.pszRootDir = TEXT("C:\\LEADTOOLS23\\Bin\\Common\\PrinterDriver"); 
       docPrinterInfo.pszPrinterName = TEXT("TestPrinter"); 
       docPrinterInfo.pszPortName = TEXT("TestPrinter"); 
       docPrinterInfo.pszMonitorName = TEXT("TestPrinter"); 
       docPrinterInfo.pszProductName = TEXT("TestPrinter"); 
       docPrinterInfo.pszRegistryKey = TEXT("SOFTWARE\\Printer\\TestPrinter"); 
       docPrinterInfo.pszUrl = TEXT(""); 
    #if defined(WIN64) 
       docPrinterInfo.pszPrinterExe = TEXT("C:\\LEADTOOLS23\\Bin\\CDLL\\x64\\LEADTOOLS IPP Demo.exe") 
       docPrinterInfo.pszPrinterExe = TEXT("C:\\LEADTOOLS23\\Bin\\CDLL\\Win32\\LEADTOOLS IPP Demo.exe"); 
    #endif // #if defined(WIN64) 
       docPrinterInfo.pszAboutString = TEXT("LEADTOOLSPrinter"); 
       docPrinterInfo.pszAboutIcon = TEXT("c:\\LEADTOOLSPrinter.ico"); 
       L_INT nRet = L_PrnInstallPrinter(&docPrinterInfo, 0); 
       SharePrinter(TEXT("TestPrinter"), TEXT("TestPrinter"), TRUE); 
       return nRet; 
    BOOL CLEADTOOLSIPPDemoDlg::SharePrinter(LPTSTR szPrinterName, LPTSTR szShareName, BOOL bShare) 
       HANDLE            hPrinter; 
       PRINTER_DEFAULTS   pd; 
       DWORD            dwNeeded; 
       PRINTER_INFO_2      *pi2; 
       ZeroMemory(&pd, sizeof(PRINTER_DEFAULTS)); 
       pd.DesiredAccess = PRINTER_ALL_ACCESS; 
       if (!OpenPrinter(szPrinterName, &hPrinter, &pd)) 
          return FALSE; 
       if (!GetPrinter(hPrinter, 2, NULL, 0, &dwNeeded)) 
          if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) 
             // GetPrinter() has failed - bail out. 
             return FALSE; 
       pi2 = (PRINTER_INFO_2*)malloc(dwNeeded); 
       if (pi2 == NULL) 
          return FALSE; 
       if (!GetPrinter(hPrinter, 2, (LPBYTE)pi2, dwNeeded, &dwNeeded)) 
          return FALS 
       pi2->pSecurityDescriptor = NULL; 
       if (bShare) 
          pi2->pShareName = szShareName; 
          pi2->Attributes |= PRINTER_ATTRIBUTE_SHARED; 
          pi2->Attributes = pi2->Attributes & (~PRINTER_ATTRIBUTE_SHARED); 
       if (!SetPrinter(hPrinter, 2, (LPBYTE)pi2, 0)) 
          // SetPrinter() has failed - bail out 
          return FALSE; 
       // Clean up. 
       return TRUE; 
    L_INT CLEADTOOLSIPPDemoDlg::EnableInternetPrinting() 
       // Enable Network Printing 
       L_INT nRet = L_PrnSetEnableNetworkPrinting(TEXT("TestPrinter"), TRUE); 
       // Enable Internet Printing 
       nRet = L_PrnSetEnableInternetPrinting(TEXT("TestPrinter"), TRUE); 
       return nRet; 
    void CLEADTOOLSIPPDemoDlg::RegisterEmfCallBack() 
       L_PrnRegisterEMFCallback(TEXT("TestPrinter"), OnEmfRgsProc, this); 
    void CLEADTOOLSIPPDemoDlg::RegisterJobCallBack() 
       L_PrnRegisterJobCallback(TEXT("TestPrinter"), OnJobInfoProc, this); 
    L_INT CLEADTOOLSIPPDemoDlg::OnEmfRgsProc(L_WCHAR * /*pszPrinter*/, 
    HGLOBAL hMem, 
    L_UINT  uSize, 
    L_VOID * pData) 
       static L_INT nCounter = 0; 
       DWORD     uSizeWritten = 0; 
       L_UCHAR * pEmfData = (L_UCHAR*)GlobalLock(hMem); 
       CString szFileName = TEXT("c:\\1.emf"); 
       if (pEmfData) 
          hFile = CreateFile(szFileName, GENERIC_WRITE, FILE_SHARE_READ, 
          if (hFile != INVALID_HANDLE_VALUE) 
             WriteFile(hFile, pEmfData, uSize, &uSizeWritten, NULL); 
       // Do not forget to free the memory. 
       return 1; 
    L_INT CLEADTOOLSIPPDemoDlg::OnJobInfoProc(L_WCHAR * pszPrinter, DWORD dwJobID, 
    DWORD dwFlags, L_VOID * pData) 
       switch (dwFlags) 
          case PRN_JOB_STAR 
             //Job was started 
             CStringA str; 
             str.Format("Job ID: %d", dwJobID); 
             MessageBoxA(NULL, str.LockBuffer(), "IPP Test Demo", 0); 
          case PRN_JOB_END: 
          //Job was ended 
       return 1; 

  16. Compile and run the code to test it. Click OK in the dialog to install a new printer, then enable internet printing and connect to it from a client machine, Try to print on the newly created printer to receive EMF and Job callback events.

Configuring Internet Printing on the Server

To configure internet printing on a computer running Windows Server 2008, perform the following steps:

  1. Run the Server Manager.
  2. Select Add Roles.
  3. Select the following roles:

    • Print and Document Services
    • Web Server (IIS)

  4. In the Role Services list, select the following services:

    • Print Server
    • Internet Printing

  5. Complete the installation.

Installing the Printer Driver on a Client Computer

To install the printer driver on a client computer, perform the following steps:

  1. In IE Explorer, open SERVER_IP/printers.

  2. Select the installed test printer named “Test Printer” and click it. The selected printer page opens.

  3. In the Printer Actions section, click Connect.

  4. Complete the installation.

See Also

Programming with the LEADTOOLS Virtual Printer Driver

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Virtual Printer C API Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.