Message Capture Service C++ Sample

 

Description:

Demonstrates how to capture the printer driver messages, using a service, sent at every

StartDoc, StartPage, EndPage, EndDoc.  This sample was created and compiled using Visual Studio 2005.

 

The purposes of the Message Capture Service C++ sample are:

 

  1. Capture messages during an automated printing as a service under an Administrator Account. The printing application is running under the service.

  2. Capture all messages for the Administrator from every User who print on the server

 

Trying the Sample

 

1.    By default, the sample will capture messages from the printer selected during the installation and create a log file to C:\MessageCaptureService.log. To change the default settings, edit the INI file, called SampleSettings.ini.

The INI file may contain the following settings:
           

            [Printer Settings]
            Printer Name=<Name of the Black Ice Printer>
            [Message Capture Service]
            logfile=<path and name of the log file>
            Message Interface ID=<Session ID>

 

           
Description of the settings:

Printer Name: Fill in the name of the Black Ice printer you want to use (without ‘<’ and ‘>’)

Logfile: The file name of the log file where you want the sample to write the messages.(If the path contains an inaccessible or non-existing folder, the log file will be generated into the Root directory of Drive C:\)

Message Interface ID: The message interface ID used by the service sample. This must be set to the same value that the driver uses. By default the Black Ice printer driver uses the Windows Session ID of the logged in user that is printing the document.

 

The Message Capture Service Sample runs isolated from the current user’s Windows Session, therefore it cannot retrieve the currently used Message Interface ID from the printer driver and the Message Interface ID must be specified manually.

 

Since Windows Vista, the first user that logs in will use 1 as the Windows Session ID. If the printer driver is set to use the Windows Session ID as the Message Interface ID (this is the default setting) and one wants to capture the messages from the first user that logged in, the Message Interface ID ini file setting should be set to 1.

Please note there are other ways to use the message interface ID, for more information about this topic, see the following page in the manual: Message Capture – Using Messaging Interface ID

 

2.  One can run the sample in two ways:

 

a.  Open a command line, navigate to the sample and start the sample with the following command:

 

Message Capture Service C++ Sample.exe –debug

 

b.  Alternatively one can use the following command to install the sample as a service:

Message Capture Service C++ Sample.exe –install
Or
Message Capture Service C++ Sample.exe –remove
To remove it

 

 

3. Start the service:

a.    Use the following command:
net start "Message Capture Service"

b.    Or use the Microsoft Services app from Control Panel / Administrative Tools / Services to start it.

 

4.    Begin printing with the Black Ice printer. The log file will be generated in the directory specified in the INI file.

 

5.    Stop the service:

a.    Use the following command:
net stop "Message Capture Service"

b.    Or use the Microsoft Services app from Control Panel / Administrative Tools / Services to stop it.

 

 

How It Works:

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

 

Sample Source Code Folder Location:

<RTK Installation Folder>\<RTK 32/64 bit>\Samples\Sample Source Codes\C++\Message Capture Service C++ Sample

 

Solution files

Compilers

Message Capture Service C++ Sample_VS2015.sln

Visual Studio 2015

Message Capture Service C++ Sample _VS2017.sln

Visual Studio 2017

Message Capture Service C++ Sample _VS2019.sln

Visual Studio 2019

Message Capture Service C++ Sample _VS2022.sln

Visual Studio 2022

 

 

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.