L_EpnCreateRedirectionDC

#include "l_eprint.h"

HDC EXT_FUNCTION L_EpnCreateRedirectionDC (pszPrinterName, pDevMode, hPrintersList, pExtraOptions)

L_CHAR L_FAR * pszPrinterName;

/* printer name */

DEVMODE L_FAR * pDevMode;

/* pointer to a structure */

HEPNPRINTERSLIST hPrintersList;

/* handle to an existing printers list */

EPNEXTRADCOPTIONS L_FAR * pExtraOptions;

/* pointer to a structure */

Creates a printer redirection device context (DC).

Parameter

Description

pszPrinterName

Character string that contains the name of the ePrint printer.

pDevMode

Pointer to a DEVMODE structure that contains specific initialization data of an ePrint printer device driver.

hPrintersList

Handle to an existing printers list, created by calling the L_EpnCreatePrintersList function.

pExtraOptions

Pointer to an EPNEXTRADCOPTIONS structure that contains additional information when using an OEM printer indirectly when the OEM printer is locked.

 

The value of this parameter will be ignored if the OEM printer is unlocked and you should pass NULL.

Returns

>0

Function was successful. The return value is the HDC.

NULL

An error occurred. To get extended error information, call the Windows C DLL GetLastError function.

Comments

Support for Basic functionality must be unlocked by calling the L_EpnUnlockSupport function before using this function.

The created DC can be used as an ordinary printer DC. Each GDI command executed for this DC will be redirected to all printers in the printers list pointed to by hPrintersList parameter.

Before using the created DC, the user should call the StartDoc and StartPage Windows C DLL functions. After using the created DC the user should call the EndPage and EndDoc Windows C DLL functions.

When the created DC is no longer needed, it should be deleted by calling L_EpnDeleteDC. For every DC created using L_EpnCreateRedirectionDC there must be a call to L_EpnDeleteDC to free it.

For OEM Printers:

If the OEM printer is locked, then the user can use it indirectly by using this function.

To use the locked OEM printer indirectly, pass a valid data to the pExtraOptions parameter. The pExtraOptions parameter is a pointer to an EPNEXTRADCOPTIONS structure. Please note that the pszPassword member of the EPNEXTRADCOPTIONS structure must be filled by the administration password that was used when the OEM printer was installed by calling the L_EpnInstallOEMPrinter function.

If the printer is locked and either NULL or an invalid password is supplied in pExtraOptions, the L_EpnCreateRedirectionDC function will fail and return NULL.

For more information, refer to Locking and Unlocking the OEM ePrint Printer.

Required DLLs and Libraries

LPKRN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to ePrint Files.

See Also

Functions:

L_EpnLockOEMPrinter, L_EpnUnlockOEMPrinter, L_EpnInstallOEMPrinter, L_EpnUninstallOEMPrinter, L_EpnCreateSaveDC, L_EpnCreateEmailDC, L_EpnDeleteDC

Topics:

ePrint: Printing indirectly to OEM Printers

 

Redirecting to a Printer Redirection List

Example

#include <Winspool.h>
L_VOID PreparePrintersList( HEPNPRINTERSLIST hPrintersList ) 
{
   DWORD dwNeededSize = 0; 
   LPTSTR pszDefaultPrinterName = NULL; 
   GetDefaultPrinter( NULL, & dwNeededSize ); 
   if( dwNeededSize > 0 ) 
   {
      pszDefaultPrinterName = (LPTSTR) GlobalAlloc( GPTR, dwNeededSize ); 
      if( pszDefaultPrinterName ) 
      {
         if( GetDefaultPrinter( pszDefaultPrinterName, & dwNeededSize ) ) 
         {
            EPNBATCHPRINTERINFO Info; 
            ZeroMemory( & Info, sizeof( EPNBATCHPRINTERINFO ) ); 
            Info.uStructSize = sizeof( EPNBATCHPRINTERINFO ); 
            lstrcpy( Info.szPrinterName, pszDefaultPrinterName ); 
            L_EpnGetDefaultEnhancedOptions( & Info.EnhOptions, sizeof( EPNENHOPTIONS ) ); 
            Info.dwFlags = EPN_BATCHPRINT_VALIDENHANCEDOPTIONS; 
            L_EpnAddPrinterToList ( hPrintersList, & Info ); 
         }
       GlobalFree( pszDefaultPrinterName ); 
      }
   }
}

L_VOID PlayGDICommands( HDC hDC, HWND hWnd ) 
{
   // Add here any GDI operations you want
   
   RECT rct; 
   GetClientRect( hWnd, & rct ); 
   BeginPath( hDC ); 
   TextOut( hDC, rct.left, rct.top, "Sample Drawing", 2 ); 
   EndPath( hDC ); 
   SelectClipPath( hDC, RGN_AND ); 
   FillRect( hDC, & rct, (HBRUSH) GetStockObject( GRAY_BRUSH ) ); 
}

#define PRINTER_NAME "LEADTOOLS ePrint 5"

L_VOID CreateRedirectionDC( HWND hWnd ) 
{
   HDC hDC = NULL; 
   DEVMODE * pDevMode = NULL; 
   
   HEPNPRINTERSLIST hPrintersList = NULL; 
   if( SUCCESS == L_EpnCreatePrintersList ( & hPrintersList ) ) 
   {
      PreparePrintersList( hPrintersList ); 
      EPNEXTRADCOPTIONS Extra; 
      ZeroMemory( & Extra, sizeof( EPNEXTRADCOPTIONS ) ); 
      Extra.uStructSize = sizeof( EPNEXTRADCOPTIONS ); 
      /* This should be the same as the password passed in the EPNOEMPRINTERINFO structure to the L_EpnInstallOEMPrinter */
      Extra.pszPassword = "Test Password";
      Extra.uReserved = 0; 
      // Pass NULL instead of the Extra parameter if the printer hadn't been locked
      hDC = L_EpnCreateRedirectionDC( TEST_PRINTER_NAME, pDevMode, hPrintersList, & Extra ); 
      /* Destroy Printers List after setting */
      L_EpnDestroyPrintersList ( hPrintersList ); 
   }
   if( hDC )  
   {
      DOCINFO DocInfo; 
      ZeroMemory( & DocInfo, sizeof( DOCINFO ) ); 
      DocInfo.cbSize = sizeof( DOCINFO ); 
      DocInfo.lpszDocName = "Test File";
      L_INT nRet = 0; 
      // Start Doc
      if(StartDoc( hDC, & DocInfo ) > 0 ) 
      {
         // Start Page
         if( StartPage( hDC ) ) 
         {
            // Do what you want with the HDC
            PlayGDICommands( hDC, hWnd ); 
            // End Page
            EndPage( hDC); 
         }
         // End Doc
         EndDoc( hDC ); 
      }
      // Delete DC
      L_EpnDeleteDC ( hDC ); 
   }
}