Take the following steps to create and run a program that uses the LEADTOOLS Network Virtual Printer Driver.
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 Projects Types, and choose Win32 Project in the Templates section. |
4. |
In the Project Name field, type the project name as "LEADTOOLS Printer Client Demo". |
5. |
In the Location field, use the Browse button to navigate to the Examples subdirectory (such as C:\LEAD Technologies\LEADTOOLS 19\Examples\CDLL). Clear both the Create Directory For Solution and Add To Source Control Check boxes. Click OK. |
6. |
Click Next> in the Win32 Project Wizard. |
7. |
Select "DLL" as the 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 and then select C/C++, then select Preprocessor. |
10. |
In right side set Preprocessor definitions property to use LTVXX_CONFIG then click OK. |
11. |
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"
12. |
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;
}
13. |
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
14. |
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.