ActiveX Interface Overview
Each of the following incoming interface types, which you can select in the Edit ActiveX Server Wizard, has advantages and disadvantages.
- Custom interface
- Dispinterface
- Dual interface
- Event interface
Keep the following points in mind when you choose an incoming interface type:
- The custom interface is the most efficient interface because it has only three additional functions.
- Scripting clients, which are client applications written in scripting languages like VBScript or JavaScript, can call functions only in late-bound interfaces, that is, indirectly through the IDispatch mechanism. If you want to make an ActiveX interface that scripting clients can use, you must choose a dispinterface or a dual interface. In addition, interface pointers in dispinterface methods and properties are treated as IUnknown or IDispatch based on their type. Therefore, NI recommends that you specify interface pointer types in dispinterface methods and properties as IUnknown or IDispatch.
- Once a custom or dual interface is registered, you must not change the entries and the order of the entries in the
interface. This restriction is referred to as interface immutability and is one of the fundamental rules of COM. If
you violate this rule, run-time errors result when applications use the interface. This rule implies that you cannot
add new methods and properties to custom and dual interfaces when you distribute a new version of your server.
In COM, you should add new functionality to objects by making the objects implement new interfaces that
represent the new functionality rather than by adding new methods and properties to existing interfaces. Because
dispinterfaces contain only the IDispatch and IUnknown functions and rely on the IDispatch functions to call their
method and property functions using DISPIDs, you can add new methods and properties to dispinterfaces safely,
without violating the immutability of these interfaces. However, the old methods and properties still are
represented by the old DISPIDs. Notice that in this case, when a client connects to an older version of the server
and calls a new method with a new DISPID that is not recognized in the older version, the client will receive a
run-time error and not cause an access violation. For this reason, you might prefer to use dispinterfaces.
The following figure shows an example of COM versioning with custom/dual interfaces. In the example, IFoo is
a custom or dual interface containing one method Foo and is implemented by version 1.0 of a COM object.
Suppose you want to add another method called Bar to the object in version 2.0. The correct way to add the method
is to create a new interface, IFoo2, which exposes both Foo and Bar methods, and make the object in version 2.0
implement both interfaces IFoo and IFoo2.
The following figure shows com versioning with dispinterfaces. In this case, you can add the Bar method to the IFoo dispinterface and implement it in the version 2.0 object. - The late-bound mechanism dispinterfaces use to call the method and property functions is slower than the early-bound mechanism.
- LabWindows/CVI and many other ActiveX client development environments support calling ActiveX server objects through custom interfaces, dispinterfaces, and dual interfaces. Other development environments support calling ActiveX server objects only through dispinterfaces.