L_PrnRegisterEMFCallback

#include "Ltprinter.h"

L_LTPRINTER_API L_INT EXT_FUNCTION L_PrnRegisterEMFCallback(pszPrinterName, fnEMFCallback, pData)

L_TCHAR * pszPrinterName;

/* printer name */

PRNEMFRGSPROC fnEMFCallback;

/* pointer to a EMF callback */

L_VOID * pData;

/* pointer to additional parameters */

Registers and enables the firing of the EMF callback function.

Parameter

Description

pszPrinterName

Character string that contains the name of the LEADTOOLS Virtual Printer Driver.

fnEMFCallback

Callback function to be registered. This callback function gets the printed job as an EMF data file.

pData

Void pointer that you can use to pass one or more additional parameters that the callback function(s) needs.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Initialize the COM library by calling the CoInitialize Windows C DLL before using callbacks. After you are finished using the callbacks release the COM library by calling the CoUninitialize Windows C DLL.

Required DLLs and Libraries

LTPRINTER

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your LEADTOOLS Virtual Printer Driver Application.

Platforms

Win32, x64.

See Also

Functions:

L_PrnUnRegisterEMFCallback, PRNEMFRGSPROC

Topics:

LEADTOOLS Virtual Printer: Register and Un-register Callback Functions

 

Working with the LEADTOOLS Virtual Printer Driver

Example

L_INT EXT_CALLBACK OnEmfRgsProc(L_WCHAR * pszPrinter,
                                HGLOBAL hMem,
                                L_UINT  uSize,
                                L_VOID * pData)
{
   UNREFERENCED_PARAMETER(pszPrinter);
   UNREFERENCED_PARAMETER(pData);

   static L_INT nCounter = 0;
   HANDLE hFile = INVALID_HANDLE_VALUE;
   DWORD  uSizeWritten = 0;
   L_UCHAR * pEmfData= (L_UCHAR*) GlobalLock( hMem );

   L_TCHAR szFileName[MAX_PATH];
   L_TCHAR szPathDir[MAX_PATH];

   GetTempPath(MAX_PATH,szPathDir);

   GetTempFileName(szPathDir,TEXT("AnyName"),0,szFileName);

   if( pEmfData )
   {
      hFile = CreateFile( szFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
      if( hFile != INVALID_HANDLE_VALUE )
      {
         WriteFile( hFile, pEmfData, uSize, & uSizeWritten, NULL );
         CloseHandle( hFile );

         HENHMETAFILE hMetaFile = GetEnhMetaFile(szFileName);

         //
         // Do what ever you need in hMetaFile then delete it
         //

         DeleteEnhMetaFile(hMetaFile);
      }
      GlobalUnlock( hMem );
   }
   // Don't forget freeing the mem.
   GlobalFree( hMem );

   return 1;
}

L_LTPRINTERTEX_API  L_VOID RegistrationEMFCallback()
{
   int nRet = L_PrnRegisterEMFCallback(TEXT("TEST LEADTOOLS Printer"),OnEmfRgsProc,NULL);

   if(nRet == SUCCESS)
   {
      L_PrnUnRegisterEMFCallback(TEXT("TEST LEADTOOLS Printer")) ;
   }
}