Admin Production ni-theme
Current Publication

Programming with ActiveX Controls

LabWindows/CVI

Programming with ActiveX Controls

ActiveX Control Drivers

In order to access the methods, properties, and events specific to an ActiveX control, you need to run the ActiveX Controller Wizard and generate an ActiveX control driver. When you include this driver in your project, you can call functions that correspond to the native interfaces of the control.

There are several ways to generate an ActiveX control driver:

  1. From the Tools menu of any LabWindows/CVI window, select Create ActiveX Controller. When you run the wizard in this manner, you need to select the ActiveX server that corresponds to your control.
  2. From the User Interface Editor, you can run the CodeBuilderCodeBuilder dialog box, by selecting Code»Generate»All Code. This dialog lists the ActiveX servers corresponding to all the controls that you created in the User Interface Editor window. For each server that you select, LabWindows/CVI runs the ActiveX Controller Wizard upon completion of the dialog.
  3. From the User Interface Editor, you can run the ActiveX Controller Wizard for a specific ActiveX control, by right-clicking the control and selecting Generate ActiveX Control Driver.

Upon completing the wizard, LabWindows/CVI loads the control driver as an instrument driver, which you can use to browse the set of available functions. By default, the wizard also includes the corresponding .fp file in your project.

For each interface that the ActiveX server supports, the driver contains a creation function that you can use to programmatically create an instance of the ActiveX control. The name of the function is of the form <InstrumentPrefix>_New<InterfaceName>. You pass to this function the panel, label and coordinates of the new control. The function returns a control ID, which you use to identify the control when you pass it to functions from the User Interface Library.

The ActiveX control driver also includes functions that you can use to register callback functions for receiving events defined by the control. You can find these registration functions in the Event Callback Registration Functions function class of the control driver.

When you use other functions in the control driver, you need to identify the control via a unique object handle, which LabWindows/CVI associates with the control. You obtain this handle when you call GetObjHandleFromActiveXCtrl. This handle is cached in the control and you do not need to discard it explicitly.

Loading ActiveX Controls from .uir Files

When you store ActiveX controls in .uir files, you do not need to use the creation functions included in the control driver. The control is created at the time that you load the panel from file, using LoadPanel. You identify the control in subsequent calls to User Interface Library functions with the constant name that you assigned to the control in the User Interface Editor.

If you wish to use functions that are part of the control driver, you need to obtain the object handle of the ActiveX control, by calling GetObjHandleFromActiveXCtrl.

Using the User Interface Library

In addition to the control driver functions, you can perform some common control operations, such as activation, resizing and copying, using the functions of the User Interface Library.

If you wish to create ActiveX controls programmatically using the User Interface Library, you can do so with the NewActiveXCtrl function . However, it is recommended that if you need to create the control programmatically, you use the functions created by the ActiveX Controller Wizard, since the control driver allows you to create ActiveX controls without having to contend with some COM-related issues, such as licensing and GUIDs.

ActiveX Document Objects

Some ActiveX controls can be associated with individual files on disk. These files, when loaded into an ActiveX control, are referred to as ActiveX Documents. You program an ActiveX document object in the same way that you would program an ActiveX control, with the only difference being that you would create an instance of a document using NewActiveXCtrlFromFile or <InstrumentPrefix>_Open<InterfaceName>, if you use the control driver. When you create an ActiveX document with these functions, you specify the file corresponding to the document.

Threading

LabWindows/CVI requires that a thread be initialized to Apartment Threading before you can use ActiveX controls in a program. If you do not initialize the thread before creating an ActiveX control, or before loading a panel containing an ActiveX control from a .uir file, LabWindows/CVI automatically initializes your thread to Apartment Threading. If you need to initialize the thread yourself, using CA_InitActiveXThreadStyleForCurrentThreadCA_InitActiveXThreadStyleForCurrentThread, you must use COINIT_APARTMENTTHREADED as the threading model.

Related Topics

Programming with Controls

ActiveX Control Functions