Take the following steps to create and run a program that uses the LEADTOOLS Network Virtual Printer Driver.
Start Visual Studio 2008.
From the Main Menu, choose File->New->Project...
In the New Project dialog box, choose Visual C++ in the Projects Types, and choose Win32 Project in the Templates section.
In the Project Name field, type the project name as "LEADTOOLS Printer Client Demo".
In the Location field, use the Browse button to navigate to the Examples subdirectory (such as C:\LEADTOOLS22\Examples\VirtualPrinter\CDLL). Clear both the Create Directory For Solution and Add To Source Control Check boxes. Click OK.
Click Next> in the Win32 Project Wizard.
Select "DLL" as the application type. Then click Finish. Three folders will be created, entitled: "Header Files", "Resource Files", and "Source Files".
From the Main Menu, choose Project->Properties.
In the Properties dialog box, choose Configuration Properties and then select C/C++, then select Preprocessor.
In right side set Preprocessor definitions property to use LTVXX_CONFIG then click OK.
In Solution Explorer, right-click the Header Files folder, open stdafx.h, and add the following code to the end of the file:
#include "..\..\..\include\ltPrinterClient.h"
Open LEADTOOLS Printer Client Demo.cpp, and add the following functions:
L_BOOL EXT_FUNCTION L_PrnClntStartup(const L_WCHAR *pszPrinterName, L_UCHAR * pbtInitialData, L_ULONG dwLenght, L_VOID ** ppUserData)
{
//set any user-defined data to ppUserData
TCHAR * szAdditionalMessage = TEXT("additional user data");
*ppUserData = malloc(_tcslen(szAdditionalMessage) * sizeof(TCHAR));
memset(*ppUserData, 0, _tcslen(szAdditionalMessage) * sizeof(TCHAR));
memcpy(*ppUserData, szAdditionalMessage, _tcslen(szAdditionalMessage) * sizeof(TCHAR));
//Function will get called as printer job starts
WCHAR szMessage[1024];
wsprintfW(szMessage, TEXT("Job received from printer %s"), pszPrinterName);
MessageBox(NULL, szMessage, TEXT("Printer Client Demo"), 0);
return TRUE;
}
L_VOID EXT_FUNCTION L_PrnClntShutdown(const L_WCHAR *pszPrinterName, L_VOID * pUserData)
{
//Function will get called when job finishes
WCHAR szMessage[1024];
wsprintfW(szMessage, TEXT("Job ended from printer %s"), pszPrinterName);
MessageBox(NULL, szMessage, TEXT("Printer Client Demo"), 0);
//free the allocated user data
free(pUserData);
}
L_BOOL EXT_FUNCTION L_PrnClntPrintJob(PRNJOBDATA* pPrintJobData, L_VOID * pUserData)
{
//Function will get called when job is being printer
WCHAR szMessage[1024];
wsprintfW(szMessage, TEXT("Job name %s"), pPrintJobData->szPrintJobName);
MessageBox(NULL, szMessage, TEXT("Printer Client Demo"), 0);
//cast the user data to the appropriate format
TCHAR * szAdditionalMessage = (TCHAR*)pUserData;
MessageBox(NULL, szAdditionalMessage, TEXT("User additional data"), 0);
char *pszMessage = "Network Printer";
pPrintJobData->hUserData = GlobalAlloc(GHND, strlen(pszMessage));
PVOID pVoid = GlobalLock(pPrintJobData->hUserData);
memcpy(pVoid, pszMessage, strlen(pszMessage));
GlobalUnlock(pPrintJobData->hUserData);
pPrintJobData->uUserDataSize = strlen(pszMessage);
return TRUE;
}
Right-click the LEADTOOLS Printer Client Demo project in the Solution Explorer, select Add->New Item..., and choose Module - Definition file ( .def ). Name it "PrinterClient.def" and add the following code to it:
LIBRARY
EXPORTS
L_PrnClntStartup @1
L_PrnClntShutdown @2
L_PrnClntPrintJob @3
Compile and run the code to test it. Now you need to connect the demo DLL to a printer.
For more information, refer to LEADTOOLS Network Printer Client Installer Demo.