1. Calling Secondary Interfaces from Visual Basic

When accessing the PI-SDK from Visual Basic, it appears on the surface that many of the properties in the hierarchy return objects. For example in the code

Dim mysrv as Server

Set mysrv = PISDK.Servers.Item("MyServer")

it appears that mysrv is a Server object. In fact the Item method returns a pointer to the Server interface, which is the default interface for the object named Server. A single COM object can support a multitude of interfaces and in many cases (such as controls) must support a host of interfaces just to be useable. In C++ you can create an instance of an object and retrieve a particular interface on the object with CoCreateInstance. With a pointer to any interface on the object you can then call QueryInterface to retrieve any other interface the object supports.

In Visual Basic, you can obtain references to secondary interfaces by using a Dim and a Set statement in a manner similar to a type cast. For example, the Server object supports an interface called IRefresh that is used to update cached data. The IRefresh interface has a single method, Refresh. You can call a Server object's Refresh method with the following code:

'Obtain the intial Server pointer

Dim mysrv as Server

Set mysrv = Servers("MyServer")

' Get the IRefresh interface

Dim srvRefresh As IRefresh

Set srvRefresh = mysrv

' If successful call it

If Not srvRefresh Is Nothing Then

srvRefresh.Refresh 

End If

If you try to get an interface from an object that does not support it, the target variable is set to Nothing. In general, you should test for Nothing immediately after the Set statement, as above.

Secondary interfaces are used in the PI-SDK for features that are orthogonal to the main purpose of the object, to expose new sets of capabilities for an object, and to upgrade an interface to fix problems or omissions in the original interface.

Enabling Operational Intelligence