Message Capture OCX VB.NET Sample

Description:

The Message Capture VB.NET sample demonstrates how to capture the printer driver messages sent at every StartDoc, StartPage, EndPage, EndDoc and ChangeDevmode event, using the PIPE interface. The sample writes a message to the list box at every ChangeDevmode event but does not change any values in the BlackIceDEVMODE structure.

 

The purposes of the Message Capture VB.NET 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

 

 

 

 

msg_capt_VB.png

 

How It Works:

The sample uses the StartCapture function of the BiPrnDrv.ocx. By default, this sample uses the Named Pipe method, which is the most compatible.

 

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 Session ID

 

Trying the Sample, Logging, Configuring

1.    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

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.

2.    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\VB.NET\Message Capture OCX VB.NET Sample  

 

Solution files

Compilers

Target .NET Framework

Message Capture OCX VB.NET Sample_VS2015.sln

Visual Studio 2015

.NET Framework 4.0

Message Capture OCX VB.NET Sample_VS2017.sln

Visual Studio 2017

.NET Framework 4.0

Message Capture OCX VB.NET Sample_VS2019.sln

Visual Studio 2019

.NET Framework 4.0

Message Capture OCX VB.NET Sample_VS2022.sln

Visual Studio 2022

.NET Framework 4.8

 

 

Additional files needed for redistribution:

-           Message Capture OCX VB.NET Sample.exe

-           blicectr.dll

-           BlackIceDEVMODE.dll

-           BlackIceDEVMODE.ocx

-           BiPrnDrv.ocx  (Needs to be registered into the OS)

-           Interop.BIPRNDRVLib.dll

-           AxInterop.BIPRNDRVLib.dll (Only for 32 bit)

-           Interop.BLACKICEDEVMODELib.dll

-           AxInterop.BLACKICEDEVMODELib.dll (Only for 32 bit)

-           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\VB.NET

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

 

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.

 

When using the BiAutoPrint and BiPrnDrv OCX 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 ChangeDevmode messages. Other messages may appear to work, but they will be delayed. This is because ChangeDevmode 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.