Registering WiT Engine callbacks

WiT Engine allows users to supply callback functions when certain events occur, such as when an image is about to be displayed or when the user needs to be prompted when the prompt operator is executed. For .Net programs, this means passing a callback from managed code to unmanaged code. To register a callback, the application must hold a strong reference to the .Net callback method to avoid it being collected as garbage, since it is used as a delegate. Because the callback is a delegate type, you must provide an actual delegate in your class.

The following example demonstrates how you register a callback for data input using the SetInputCallback method.

[C#]
public class Form1 : System.Windows.Forms.Form
{
    ...
    private WiT.engine.inputCB myInCallback;
    ...
    public void Form1_Load()
    {
        ...
        myInCallback = new WiT.engine.inputCB(needData);
        WiT.engine.SetInputCallback("sample", myInCallback);
        ...
    }
    ...
    public void needData(string name)
    {
    }
    ...
}

[Visual Basic]
Public Class Form1
    ...
    Private myInCallback As WiT.engine.inputCB
    ...
    Public Sub Form1_Load()
        ...
        myInCallback = New WiT.engine.inputCB(AddressOf needData)
        WiT.engine.SetInputCallback("sample", myInCallback)
        ...
    End Sub
    ...
    Public Sub needData(ByVal name As String)
    End Sub
    ...
End Class

 

Up 

Next