Changing the Output Directory through the API for a Print Job using the Messaging Interface C# Sample code

private const string PrinterName = "Black Ice ColorPlus";

 

// Add reference to these ActiveX controls

private BIPRNDRVLib.BiPrnDrv BiPrnDrv;

private BLACKICEDEVMODELib.BlackIceDEVMODE BlackIceDEVMODE;

 

// This function retrieves the current Message Interface ID used by the Printer Driver.

// This is optional because both the Printer Driver and the Message Capture ActiveX control

// uses the current user's Session ID by default.

private int GetCurrentMessageInterfaceID()

{

    // Load the current user's DEVMODE structure

    int pDevMode = BlackIceDEVMODE.LoadBlackIceDEVMODE(PrinterName); // "long pDevMode" for the 64 bit OCX

 

    // Get the Message Interface ID used by the Printer Driver

    int id = BlackIceDEVMODE.GetSessionID(pDevMode);

 

    // Free the structure

    BlackIceDEVMODE.ReleaseBlackIceDEVMODE(pDevMode);

 

    return id;

}

 

private void StartCapture()

{

    BiPrnDrv = new BIPRNDRVLib.BiPrnDrv();

    BlackIceDEVMODE = new BLACKICEDEVMODELib.BlackIceDEVMODE();

 

    // Add event handler

    BiPrnDrv.ChangeDevmode += new

      BIPRNDRVLib._DBiPrnDrvEvents_ChangeDevmodeEventHandler(BiPrnDrv_ChangeDevmode);

 

    // Setting the Message Interface ID of the Message Capture ActiveX control.

    // This is optional because both the Printer Driver and the Message Capture ActiveX control

    // uses the current user's Session ID by default.

    BiPrnDrv.SessionID = GetCurrentMessageInterfaceID();

 

    // Starting the message capture

    BiPrnDrv.StartCapture(PrinterName, 3); // 3: MESSAGE_CAPTURE_METHOD_PIPE

}

 

private void StopCapture()

{

    BiPrnDrv.StopCapture();

 

    // remove event handler

    BiPrnDrv.ChangeDevmode -= new

      BIPRNDRVLib._DBiPrnDrvEvents_ChangeDevmodeEventHandler(BiPrnDrv_ChangeDevmode);

}

 

private void BiPrnDrv_ChangeDevmode(int pDevMode) // "long pDevMode" for the 64 bit OCX

{

    // Set file name generation method to exact filename

    BlackIceDEVMODE.SetFileGenerationMethod(3, pDevMode); // 3: FILENAME_EXACT_DEVMODE

    // Set the filename (you can give a full path here)

    BlackIceDEVMODE.SetImageFileName("name.pdf", pDevMode);

}

 

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.