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 MFC Application in the Templates. |
4. |
Type the project name as LEADTOOLS Printer Server Demo in the Project Name field. |
5. |
In the Location field, use the Browse button to navigate to the Examples subdirectory (such as C:\LEAD Technologies\LEADTOOLS 19\Examples\CDLL). Uncheck both Create directory for solution and Add to Source Control options. 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. |
In right side set 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 "..\..\..\Include\Ltprinter.h"
12. |
In the Source Files, right -click on 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 on 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\\Ltdlgfile_x.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\cdll\\x64\\Ltdlgkrn_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")#else#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\\Ltdlgfile_u.lib")#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\cdll\\win32\\Ltdlgkrn_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 on LEADTOOLS Printer Server DemoDlg.h and click Open. Add the following function definitions to CLEADTOOLSPrinterServerDemoDlg 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_VOID RegisterJobCallBack();L_VOID RegisterEmfCallBack();L_INT InstallPrinter();
15. |
Right-click on LEADTOOLS Printer Server DemoDlg.cpp and click Open. Add the following function: |
//Locate BEGIN_MESSAGE_MAP(CLEADTOOLSPrinterServerDemoDlg, CDialog) and add the functionsON_BN_CLICKED(IDOK, &CLEADTOOLSPrinterServerDemoDlg::OnBnClickedOk);//Add the following functions implementationsvoid CLEADTOOLSPrinterServerDemoDlg::OnBnClickedOk(){InstallPrinter();RegisterEmfCallBack();RegisterJobCallBack();}L_INT CLEADTOOLSPrinterServerDemoDlg:: InstallPrinter (){PRNPRINTERINFO docPrinterInfo;memset(&docPrinterInfo, 0, sizeof(PRNPRINTERINFO));docPrinterInfo.uStructSize = sizeof(PRNPRINTERINFO);docPrinterInfo.pszRootDir = TEXT("C:\\LEADTOOLS 19\\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("https://www.leadtools.com");docPrinterInfo.pszPassword = TEXT("123");docPrinterInfo.pszPrinterExe = TEXT("c:\\TestDemo.exe");docPrinterInfo.pszAboutString = TEXT("LEADTOOLSPrinter");docPrinterInfo.pszAboutIcon = TEXT("c:\\LEADTOOLSPrinter.ico");L_INT nRet = L_PrnInstallPrinter(&docPrinterInfo, 0);return nRet;}void CLEADTOOLSPrinterServerDemoDlg::RegisterEmfCallBack(){L_PrnRegisterEMFCallback(TEXT("TestPrinter"),OnEmfRgsProc,this);}void CLEADTOOLSPrinterServerDemoDlg::RegisterJobCallBack(){L_PrnRegisterJobCallback(TEXT("TestPrinter"),OnJobInfoProc,this);}L_INT CLEADTOOLSPrinterServerDemoDlg::OnEmfRgsProc( L_WCHAR * /*pszPrinter*/,HGLOBAL hMem,L_UINT uSize,L_VOID * pData ){static L_INT nCounter = 0;HANDLE hFile = INVALID_HANDLE_VALUE;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,NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);if( hFile != INVALID_HANDLE_VALUE ){WriteFile( hFile, pEmfData, uSize, & uSizeWritten, NULL );CloseHandle( hFile );}GlobalUnlock( hMem );}// Don't forget freeing the mem.GlobalFree( hMem );return 1;}// You need always to free hMem.L_INT CLEADTOOLSPrinterServerDemoDlg::OnJobInfoProc( L_WCHAR * pszPrinter, DWORD dwJobID,DWORD dwFlags, L_VOID * pData ){switch( dwFlags ){case PRN_JOB_START:{//Job was startedPRNJOBDATA jobData;L_PrnGetRemoteData(pszPrinter, dwJobID, &jobData);PCHAR pChar = (PCHAR)malloc(jobData.uUserDataSize + 1);PVOID pVoid = GlobalLock(jobData.hUserData);memcpy(pChar, pVoid, jobData.uUserDataSize);GlobalUnlock(jobData.hUserData);GlobalFree(jobData.hUserData);pChar[jobData.uUserDataSize] = NULL;CStringA str;str.Format("Job recieved with message %s", pChar);MessageBoxA(NULL, str.LockBuffer(), "Printer Server Demo", 0);free(pChar);}break;case PRN_JOB_END://Job was endedbreak;}return 1;}
16. |
Compile and run the code to test it, Click OK button in the dialog to install new printer then share the printer, and connect to it from a client machine, try to print on created printer to receive EMF and Job callback events. |
For more information, refer to:
Working with the LEADTOOLS Virtual Printer
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
