LogWeb/Ajax API for MS Office applications

LogWeb/Ajax API in VisualBasic 6 applications

You can easily integrate the LogWeb/Ajax API into Visual Basic applications.

In both cases, LogWeb/Ajax must be loaded in the objects so that it can use the API.

To access the API, the IHTMLWindows2 interface is required, which can be reached using HTMLDocument.parentWindow.

You reference variables and methods as described in the LogWeb/Ajax API documentation. However, the name of your IHTMLWindows2 object comes before the method. For example, the call for querying the row of the cursor position is: engine.lwh.current.field.row, where engine is the IHTMLWindow2 object.

You must pass a parameter to JavaScript functions that have no parameters so that the scripting engine executes the script instead of returning the script name.

Using the execScript function of the IHTMLWindow2 interface, you can execute your own JavaScript code fragments in HTMLDocument.

In rare cases, you must customize the API, for example, to solve problems involving type conversion, especially for return values. This can be necessary when the return value is an object type that has no equivalent in Visual Basic. In this case, you define a JavaScript function that you declare over execScript in HTMLDocument. This function encapsulates the original API method and executes the type conversion that conforms with Visual Basic. Now you can use this new method like any other LogJava/Ajax API function.

You can implement callback functions by assigning a Visual Basic object to the JavaScript function variable. A special aspect is that this must be an instance of a Visual Basic class, and that this class must have a default method. The reason for this is that the scripting engine identifies the value of a variable by taking each variable as an object and calling the default method of each variable.
For this, Visual Basic must generate a COM object from the class declaration.
To be able to set the necessary properties, a Visual Basic project of the ActiveX type is required. For a GUI application, you must declare the start method in the project properties and, on the Component tab, set the property Start Mode to "Standard".

The class gets the attribute "Instancing=2 PublicNotCreatable", so that it becomes visible as a COM object but cannot be instanced.

project instance

To set the default procedure ID of the method, open the code window of the class and assign the default ID to the method using the Tools->Procedure Attributes menu.

procedure attributes

LogWeb/Ajax API in Visual Basic .NET applications

The use of LogWeb/Ajax API in Visual Basic .NET differs only slightly from its use in Visual Basic 6 applications. The main difference is the differentiation between managed and unmanaged code and the threading model.

Functions of the LogWeb/Ajax API can easily be called from the managed code environment. The common language runtime (CLR) automatically executes data marshaling and unmarshaling and generates, if necessary, on the fly Proxy-COM objects.

Callbacks from the LogWeb/Ajax API need special preparation, because in order to process callback methods, the CLR draws a thread from its thread pool, which usually runs in the default, multithread apartment (MTA). Like Windows GUI objects, IHTMLWindow2 objects need the single threaded apartment (STA) environment. The thread property "ApartmentState" cannot simply be changed, because this property cannot be changed afterwards. Therefore, in the example, a dedicated worker thread is used, to which all callback calls are delegated to ensure the processing in the STA.

In contrast to VB 6, no COM interfaces are generated for classes, because the instances usually exist only in the managed code context. However, for callbacks Proxy-COM objects for the unmanaged code part are needed. For example, the COM interface must be explicitly declared, and this interface must be implemented in the relevant managed code. As in VB 6, the default method gets the <DispID(0)> attribute so that the scripting engine uses this method.

Note that the interface name needs the prefix '_', and that the corresponding class must have the same name, but without the prefix '_'

<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> Public Interface _CallbackOnInput<DispId(0)>
    Sub onKeyInput(ByVal aChar As String)
End Interface
<ClassInterface(ClassInterfaceType.None)> Public Class CallbackOnInput Implements _CallbackOnInput
    Public Sub onKeyInput(ByVal aChar As String) Implements _CallbackOnInput.onKeyInput
    ...
    End Sub
End Class

Due to security reasons, the callback of LogWeb/Ajax is prevented and the CLR dispatches a security exception. To avoid this, the System.Security.Permissions must be changed or the application must be signed.