Print to memory (Memory Image) C++ Sample

 

Description:

Demonstrates how to capture and save PDF, TIFF, BMP or EMF images, OCR data printed and text data printed into memory with the Black Ice ColorPlus, Color, Monochrome and EMF Printer Drivers by using the “Generate output in                 memory” , "Generate OCR output in memory" and  "Generate text output in memory" options of the printer driver for HIIPA compliant application.

 

print_mem_C++.png

 

How It Works:

The printer drivers uses a named pipe interface to communicate with the application. The BLICECTR.DLL captures the pipe messages sent by the printer driver and converts them to window messages “WM_” to be used by the application.

 

NOTE: The printer driver adds a Message Interface ID to the interface name. By default the sample and the OCX uses the Message Interface ID that is currently used by the printer driver, and the printer driver uses the Windows Session ID of the current user as the Message Interface ID. For more information about the Message Interface ID including instructions about how to change the Message Interface ID used by the printer driver, please see the following page in the manual: Message Capture – Using Messaging Interface ID

 

Override the Message Interface ID

To override the Message Interface ID, one must set the Message Interface ID key in the SampleSettings.ini file:

 

[Print to Memory] 

Message Interface ID=15

 

The sample will change the Message Interface ID of the Driver to the specified value.

If the Message Interface ID key is not set in the INI file or it is set to -1, the current printer setting is used.

 

NOTE: If the Sample applications is set to override the current Message Interface ID, the Sample must be started earlier than the printing application.

 

For more details and other message capture methods, please see the Messaging Interfacesection of the manual

 

Logging, Changing the Settings

Edit the INI file of Sample, called SampleSettings.ini. The following option must be specified in the INI file:

[Printer Settings]

Printer Name=<Name of the Black Ice Printer>

[Print to Memory]

logfile=c:\PrinttoMemory.log

Message Interface ID=-1

 

Description of the settings:

Printer name: Fill in the name of the Black Ice printer to be used by the Sample (without ‘<’ and ‘>’)

 

logfile: Specifies the log file’s location and name. The sample logs every messages during the printing.

 

Message Interface ID: Sets the Message Interface ID of the Printer to the specified value. If this value is not set, or set to -1, the sample uses the printer’s current setting. To run multiple instances of the Message Capture Sample using different Message Interface IDs, make  separate copies of the Message Capture Sample and the necessary files listed in the Additional files needed for redistribution section below, in separate directories. This way you can set each copy to a different Printer and Message Interface ID.

 

Trying the Sample:

Open the Black Ice printer driver’s Printing Preferences window, on the File Formats tab select a suitable format (PDF, TIFF, BMP or EMF) and check the Generate output in memory box.

 

Make sure that the Messaging Interface is enabled in the Printer Driver Printing Preferences > Start Application tab:

 

 

OCR data(feature is available from version 14.98)

The sample can read the OCR data from memory, if the Generate OCR output in memory feature is enabled

The extension of the Plain Text OCR format is txt

The extension of the hOCR format is html

 

Text data (feature is available from version 14.99)

The sample can read the text data from memory, if the Generate text output in memory feature is enabled

Start the sample application and begin printing. The sample will save the image to the disk, to the location written in the sample window.

 

Sample Source Code Folder Location:

<RTK Installation Folder>\<RTK 32/64 bit>\Samples\Sample Source Codes\C++\Print to Memory C++ Sample

 

Solution files

Compilers

Print to Memory C++ Sample_VS2015.sln

Visual Studio 2015

Print to Memory C++ Sample _VS2017.sln

Visual Studio 2017

Print to Memory C++ Sample _VS2019.sln

Visual Studio 2019

Print to Memory C++ Sample _VS2022.sln

Visual Studio 2022

 

 

Files needed for redistribution:

 

-   blicectr.dll

-   INI file (Optionally change the printer name in the ini file):

-   SampleSettings.ini

 

Warning: You must copy the appropriate dll files to the project folder.

 

For detailed instructions on how to create a new project, please refer to the Creating a new project that uses message capture and the print to memory feature section.

 

Note: Please make sure that you use the appropriate Resource ToolKit, there are two different RTKs.

- API/RTK for 32/64 bit Windows 11,10, 8.1, 7

- API/RTK for 32/64 bit Windows Server 2022/2019/2016/2012

 

Using Message Capture and Printing from the Same Process

 

If you wish to extend the Message Capture samples with printing using AutoPrint, or otherwise combine message capture and printing in the same application, the printing thread must be separated from the message capture thread.

 

Printing and capturing messages from the same thread will result in lost BLACKICE_MESSAGE_DEVMODE messages. Other messages may appear to work, but they will be delayed. This is because BLACKICE_MESSAGE_DEVMODE messages will wait for response and eventually time out, while other messages do not wait for response and are queued.

 

Limitations:

A single instance of Printer Driver can interface with either a “Message Capture” sample application or with a “Print to Memory” sample application at the same time.