Virual Printer Tutorials: Sample Client Application
Sample client application used for testing and development purposes. This application demonstrates how to transfer information into an application. You can view the generated files by double clicking the line containing the file path.

To open the Properties Dialog for the Virtual Printer, click the Printer Preferences button.

What you need to create a Sample Client Application in C++/MFC
Read the registry to get the transfer mode used to send the INI file path from the virtual printer to the specified client application.
This option is stored in the registry branch "HKEY_LOCAL_MACHINE\SOFTWARE\Your Virtual Printer Example". The key is "Transfer Mode". In C++/MFC, the value of this parameter can be taken as follows:
// Get transfer mode related settings from the printer configuration
HKEY hKey = NULL;
DWORD dwSize = 0;
CString sKeyName;
CString sRegistryKey = "Your Virtual Printer Example";
sKeyName.Format("Software\\%s", sRegistryKey);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKeyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
RegQueryValueEx(hKey, "Transfer Mode", NULL, NULL, (BYTE*) &m_iTransferMode, &(dwSize = sizeof(int)));
RegCloseKey(hKey);
}
Get the path to the INI file. The virtual printer sends the path of this INI file to a specified application using one of following transfer modes:
Command line transfer mode. The virtual printer will run the specified application with the path of the INI file in the command line parameters. For this method, we recommend using the following method of obtaining content from the command line:
CString sInputIniFilePath = AfxGetApp()->m_lpCmdLine;
WM_COPYDATA transfer mode. The printer runs the specified application (or looks for a running instance) and sends it the path of the INI file using a WM_COPYDATA message.
// If message ID is equal to ID from the COPYDATASTRUCT then the message is received from the EMF printer int iMessageID; RegQueryValueEx(hKey, "Message ID", NULL, NULL, (BYTE*) &iMessageID, &(dwSize = sizeof(int))); if (iMessageID == (int) pCopyDataStruct->dwData) { // Get the file name from the message data CString sInputIniFilePath = (char*) pCopyDataStruct->lpData; }Clipboard transfer mode. (This is obsolete and intended for legacy applications.) The printer runs the specified application (or looks for a running instance), puts the path of the INI file on the clipboard, and notifies the application.
// Analyze all messages from WM_APP range, check if the message has been //received from the EMF printer CString sClipboardFormat; if ((uMsg >= WM_APP) && (uMsg <= 0xBFFF) && ((int) uMsg == m_iMessageID)) { RegQueryValueEx(hKey, "Clipboard Format", NULL, NULL, (BYTE*) sClipboardFormat.GetBuffer(256), &(dwSize = 256)); sClipboardFormat.ReleaseBuffer(); // Register clipboard format UINT uClpFmt = RegisterClipboardFormat(sClipboardFormat); // Open the clipboard if (OpenClipboard()) { // Read data from the clipboard HANDLE h; if (h = GetClipboardData(uClpFmt)) { CString sInputIniFilePath = (char*) GlobalLock(h); GlobalUnlock(h); CloseClipboard(); } } }
Parse the INI file with print job information and paths to the generated files. In C++/MFC it can be done as follows:
char szBuf[512] = {0};
CString sTemp;
// Show device name
GetPrivateProfileString("Device", "DeviceName", NULL, szBuf, sizeof(szBuf), sInputIniFilePath);
// Show print job (document) page count
GetPrivateProfileString("Document", "Pages", NULL,szBuf, sizeof(szBuf), sInputIniFilePath);
iCount = GetPrivateProfileInt("EMF", "Count", 0, sInputIniFilePath);
for (j = 0; j < iCount; j++)
{
sTemp.Format("File%d", j);
GetPrivateProfileString("PDF", sTemp, NULL, szBuf, sizeof(szBuf), sInputIniFilePath);
}
Download Sample Client Application:
Virtual Printer for C++/MFC
Virtual Printer for Delphi
Virtual Printer for C#
Virtual Printer for VB.Net
Virtual Printer for VB6
Virtual Printer for few languages