Creating the ActiveX event server object

Return values

The sample code below, written in Microsoft Visual Basic 5.0 (VB5), illustrates the process of creating an ActiveX event server object.

For this code example to work, you must use the class name Root and name the EventServer.exe file.

Public MyApplication As Object

Public Function Connect(EHApp As Object)

Set MyApplication = EHApp

MsgBox "EventServer.Root.Connect()"

End Function

Public Function JobStarted() As Long

MsgBox "EventServer: JobStarted()"

JobStarted = 0 ‘EV_OK, Return value to Kofax ReadSoft Invoices

End Function

This code belongs to a VB5 class called "Root". Unless you are following this specific example, you can name the class anything you like, but you need to know the name when you create it from ReadSoft Invoices. In VB5, the name of the project and the name of the class is the name that becomes the registered class name.

The class has one member variable, called MyApplication. The name is carefully chosen to match the name of ReadSoft Invoices' one and only global variable that provides the root of the object hierarchy.

The MyApplication variable is initialized in the Connect method called from the program. When ReadSoft Invoices calls the Connect method, the method passes a reference to the ReadSoft Invoices MyApplication object so that the external event server object can access the methods and properties provided by the program.

The JobStarted() function above has the same name as the JobStarted event in ReadSoft Invoices and is executed when the JobStarted event is fired.

The external event handlers must have the correct return value if ReadSoft Invoices is to respond appropriately

EV_ERROR (-1): An error occurred in the event handler. The job is terminated.

EV_OK (0): Event handled, proceed normally.

EV_OK_ABORT (1): The job is terminated.

Note When you define an event handler using the internal VBA, ReadSoft Invoices automatically names it with the prefix "On", for example OnJobStarted, OnInvoiceComplete. If these event handlers are written in an ActiveX automation object, they must not be named OnJobStarted and OnInvoiceComplete but JobStarted and InvoiceComplete.

All the event handlers must be located inside the object that you register with ReadSoft Invoices. Of course, you can call any other objects and methods from those event handlers, but execution starts in the method located in the object registered as the event server.

Related topics

Using an external event server object

ActiveX object registration in Windows

Setting an ActiveX object as Kofax ReadSoft Invoices' event server