Capturing Messages from Multiple Non-parallel Printers:
Using the Message Capture with multiple non-parallel printers is possible by setting the printers to use the same messaging interface name. The Messaging Interface Name can be set in the InterfaceName key in the Printer Driver’s INI file. For more information about the Printer Driver’s INI file, please see the following page in the manual: http://www.blackice.com/private/rtk/The_Printer_Driver_INI_Files.htm
Capturing Messages from Multiple Parallel Printers:
It is also possible to listen to multiple parallel printers. But in this case every printer must use a separate messaging interface name. Multiple BiPrnDrv objects must be used, one for each printer. A separate thread must be created for each BiPrnDrv object and the COM apartment model of the threads must be set to STA before the thread is started. Application.DoEvents() must be called inside the thread to process the messages.
When using separate printer driver for each parallel printer, every printer has a separate INI file, so the messaging interface name can be specified for each printer in the INI files. When using parallel printers that use the same printer driver, the INI file is shared between the printers, so the messaging interface name must be set using the SetInterfaceName API function, before the message capture is started.
The following code example starts the message capture for two parallel printers that are set to use a unique message interface name, prints a document to each printer, waits for the documents to be printed, then exits:
string[] printers;
Thread[] threads;
void MessageCaptureThread(object PrinterName)
{
// Create BiPrnDrv object and start the Message Capture
BIPRNDRVLib.BiPrnDrv biprnrv = new BIPRNDRVLib.BiPrnDrv();
bool stopcapture = false;
BIPRNDRVLib._DBiPrnDrvEvents_EndDocEventHandler endDoc =
(GroupFileName) =>
{
// In this example we stop the message capture after a single document
// has been printed to the printer. Of course, this can be modified.
stopcapture = true;
};
biprnrv.EndDoc += endDoc;
biprnrv.StartCapture((string)PrinterName, 3);
// Wait until the EndDoc message is recieved
while (!stopcapture)
{
System.Threading.Thread.Sleep(100);
Application.DoEvents();
}
// Stop the message Capture and free the BiPrnDrv object
biprnrv.StopCapture();
biprnrv.EndDoc -= endDoc;
Marshal.FinalReleaseComObject(biprnrv);
}
void Start()
{
printers = new string[] { "Black Ice ColorPlus", "Black Ice ColorPlus 2" };
threads = new Thread[printers.Length];
// Create Message Capture Threads
for (int i = 0; i < printers.Length; i++)
{
threads[i] = new Thread(
new ParameterizedThreadStart(MessageCaptureThread));
// Set apartment state to single threaded
threads[i].SetApartmentState(ApartmentState.STA);
// Start the Message Capture Thread
threads[i].Start(printers[i]);
}
}
void Stop()
{
// Wait for All of the Message Capture Threads to finish
for (int i = 0; i < printers.Length; i++)
{
threads[i].Join();
}
}
void Test()
{
// Start Message Capture Threads
Start();
// Print documents...
PrintTo("Black Ice ColorPlus");
PrintTo("Black Ice ColorPlus 2");
// Wait for the Message Capture Threads to finish
Stop();
}