Message Capture Service OCX C# Sample

Description:

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

StartDoc, StartPage, EndPage, EndDoc, ChangeDevmode and MemoryImage.  This sample was created and compiled using Visual Studio 2015.

 

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. Install the service

a.    Open a command line with administrator privileges and use the
"Message Capture Service OCX C# Sample.exe" –install
command to install the sample as a service or
"Message Capture Service OCX C# Sample.exe" –remove
to remove it.

b.    Alternatively, use the Installutil.exe utility of the .NET framework. For more information please see: http://msdn.microsoft.com/en-us/library/50614e95(v=vs.80).aspx

3.    Start the service

a.    Use the following command:

net start "Black Ice Message Capture Service OCX C# Sample"

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. (C:\MessageCaptureService.log by default)

5.    Stop the service

a.    Use the following command:
net stop "Black Ice Message Capture Service OCX C# Sample"

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 BiPrnDrv.ocx captures the pipe messages sent by the printer driver and converts them to events, handled by the service.

 

Sample Source Code Folder Location:

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

 

Solution files

Compilers

Target .NET Framework

Message Capture Service OCX CS Sample_VS2015.sln

Visual Studio 2015

.NET Framework 4.0

Message Capture Service OCX CS Sample_VS2017.sln

Visual Studio 2017

.NET Framework 4.0

Message Capture Service OCX CS Sample_VS2019.sln

Visual Studio 2019

.NET Framework 4.0

Message Capture Service OCX CS Sample_VS2022.sln

Visual Studio 2022

.NET Framework 4.8

 

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

 

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.