Message Capture DLL C# Sample

Description:

The Message Capture DLL C# sample demonstrates how to capture the printer driver messages sent at every BLACKICE_MESSAGE_STARTDOC, BLACKICE_MESSAGE_STARTPAGE, BLACKICE_MESSAGE_ENDPAGE, BLACKICE_MESSAGE_ENDDOC, BLACKICE_MESSAGE_ABORT and BLACKICE_MESSAGE_DEVMODE message

The sample writes a message to the list box at every message but does not change any values in the BlackIceDEVMODE structure.

 

The purposes of the Message Capture DLL C# sample are:

1.    Capture messages from the Printer Driver for the User in the current Windows Session

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

 

 

How It Works:

The sample uses the WaitForPrnPipeWithPriority (Start button) and EndWaitPrnPipe (Stop button) function of the blicectr.dll. The printer driver uses a named pipe interface to communicate with the application.

 

Trying the Sample, Logging, Configuring

3.   Edit the INI file of the Sample called SampleSettings.ini.

The following options can be specified in the INI files:

[Printer Settings]

Printer Name=<Name of the Black Ice Printer>

[Message Capture]

logfile=c:\MessageCapture.log

 

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.

4.    Start the sample application, and start printing to the configured printer driver. The captures messages must appear on the sample’s user interface

 

Sample Source Code Folder Location:

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

 

Solution files

Compilers

Target .NET Framework

Message Capture Dll CS Sample_VS2015.sln

Visual Studio 2015

.NET Framework 4.0

Message Capture Dll CS Sample_VS2017.sln

Visual Studio 2017

.NET Framework 4.0

Message Capture Dll CS Sample_VS2019.sln

Visual Studio 2019

.NET Framework 4.0

Message Capture Dll CS Sample_VS2022.sln

Visual Studio 2022

.NET Framework 4.8

 

Additional files needed for redistribution:

-           Message Capture DLL C# Sample.exe

-           blicectr.dll

-           BlackIceDEVMODE.dll

-           SampleSettings.ini (Optional: Change printer name from ini file)

 

These additional files are located in the following folders.

\<RTK Installation Folder>\<RTK 32/64 bit>\BiPrnDrv

            \<RTK Installation Folder>\<RTK 32/64 bit>\BlackiceDEVMODE

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

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

 

Note: Please make sure that you use the appropriate Resource Tool Kit, 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 R2/2012R2

 

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.

 

When using the BiAutoPrint and BiPrnDrv DLL controls from the same application in .NET languages, the controls must be created and initialized on a separate thread, because .NET will call the controls from the thread they were created on, using an invocation mechanism, even if you access the objects from a separate 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.