Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Using ActiveX with LabVIEW

LabVIEW 8.2 Help
August 2006

NI Part Number:
371361B-01

»View Product Info
Download Help (Windows Only)

You can use LabVIEW as an ActiveX client to access the objects, properties, methods, and events associated with other ActiveX-enabled applications. LabVIEW also can act as an ActiveX server, so other applications can access LabVIEW objects, properties, and methods. Refer to ActiveX and LabVIEW at ni.com for more information about using ActiveX with LabVIEW.

ActiveX Objects, Properties, Methods, and Events

ActiveX-enabled applications include objects that have exposed properties and methods that other applications can access. Objects can be visible to the users, such as buttons, windows, pictures, documents, and dialog boxes, or invisible to the user, such as application objects. You access an application by accessing an object associated with that application and setting a property or invoking a method of that object.

Events are the actions taken on an object, such as clicking a mouse, pressing a key, or receiving notifications about things such as running out of memory or tasks completing. Whenever these actions occur to the object, the object sends an event to alert the ActiveX container along with the event-specific data. The ActiveX object defines the events available for an object.

ActiveX VIs, Functions, Controls, and Indicators

Use the following VIs, functions, controls, and indicators to access the objects, properties, methods, and events associated with other ActiveX-enabled applications:

  • Use the automation refnum control to create a reference to an ActiveX object. Right-click this control on the front panel to select an object from the type library you want to access.
  • Use the Automation Open function to open an ActiveX object.
  • Use the ActiveX container to access and display an ActiveX object on the front panel. Right-click the container, select Insert ActiveX Object from the shortcut menu, and select the object you want to access.
  • Use the Property Node to get (read) and set (write) the properties associated with an ActiveX object.
  • Use the Invoke Node to invoke the methods associated with an ActiveX object.
  • Use the Register Event Callback function to handle events that occur on an ActiveX object.
  • Use the variant control and indicator to pass data to or from ActiveX controls.

LabVIEW as an ActiveX Client

When LabVIEW accesses the objects associated with another ActiveX-enabled application, it is acting as an ActiveX client. You can use LabVIEW as an ActiveX client in the following ways:

  • Open an application, such as Microsoft Excel, create a document, and add data to that document.
  • Embed a document, such as a Microsoft Word document or an Excel spreadsheet, on the front panel in a container.
  • Place a button or other object from another application, such as a Help button that calls the other application help file, on the front panel.
  • Link to an ActiveX control you built with another application.

LabVIEW accesses an ActiveX object with the automation refnum control or the ActiveX container, both of which are front panel objects. Use the automation refnum control to select an ActiveX object. Use the ActiveX container to select a displayable ActiveX object, such as a button or document and place it on the front panel. Both objects appear as automation refnum controls on the block diagram.

Accessing an ActiveX-Enabled Application

To access an ActiveX-enabled application, use the automation refnum control on the block diagram to create a reference to an application. Wire the control to the Automation Open function, which opens the calling application. Use the Property Node to select and access the properties associated with the object. Use the Invoke Node to select and access the methods associated with the object. Close the reference to the object using the Close Reference function. Closing the reference removes the object from memory.

For example, you can build a VI that opens Microsoft Excel so it appears on the user's screen, creates a workbook, creates a spreadsheet, creates a table in LabVIEW, and writes that table to the Excel spreadsheet.

Refer to the Write Table To XL VI in the labview\examples\comm\ExcelExamples.llb for an example of using LabVIEW as an Excel client.

Note   Applications that include ActiveX custom interfaces appear with a icon. Click the icon to select an object for the custom interface.

Inserting an ActiveX Object on the Front Panel

To insert an ActiveX object on the front panel, right-click the ActiveX container, select Insert ActiveX Object from the shortcut menu, and select the ActiveX control or document you want to insert. You can set the properties for an ActiveX object using the ActiveX Property Browser or property pages, or you can set the properties programmatically using the Property Node.

Use the Invoke Node to invoke the methods associated with the object.

For example, you can display a Web page on the front panel by using an ActiveX container to access the Microsoft Web Browser control, selecting the Navigate class of methods, selecting the URL method, and specifying the URL.

If you use the ActiveX container, you do not have to wire the automation refnum control on the block diagram to the Automation Open function or close the reference to the object using the Close Reference function. You can wire directly to the Invoke Node or Property Node because the ActiveX container embeds the calling application in LabVIEW. However, if the ActiveX container includes properties or methods that return other automation refnums, you must close these additional references.

Design Mode for ActiveX Objects

Right-click an ActiveX container and select AdvancedDesign Mode from the shortcut menu to display the container in design mode while you edit the VI. In design mode, events are not generated and event procedures do not run. The default mode is run mode, where you interact with the object as a user would.

Setting ActiveX Properties

After you open an ActiveX server or insert an ActiveX control or document, you can set the properties associated with that control or document using the ActiveX Property Browser, property pages, and the Property Node.

ActiveX Property Browser

Use the ActiveX Property Browser to view and set all the properties associated with an ActiveX control or document in an ActiveX container. To access the ActiveX Property Browser, right-click the control or document in the container on the front panel and select Property Browser from the shortcut menu. You also can select Tools.NET & ActiveXBrowse ActiveX Properties. The ActiveX Property Browser is an easy way to set the properties of an ActiveX object interactively, but you cannot use the browser to set properties programmatically, and you can use the ActiveX Property Browser only with ActiveX objects in a container. The ActiveX Property Browser is not available in run mode or while a VI runs.

ActiveX Property Pages

Many ActiveX objects include property pages, which organize the properties associated with the object on separate tabs. To access ActiveX property pages, right-click the object in the container on the front panel and select the name of the object from the shortcut menu.

Like the ActiveX Property Browser, ActiveX property pages are an easy way to set the properties of an ActiveX object interactively, but you cannot use them to set properties programmatically, and you can use property pages only with ActiveX objects in a container. Property pages are not available for all ActiveX objects. Property pages also are not available in run mode or when the VI is running.

Property Nodes

Use the Property Node to set ActiveX properties programmatically. For example, if you use an ActiveX object to warn a user when a temperature exceeds a limit, use the Property Node to set the Value property of the object to specify the limit.

The following block diagram shows an example that changes the Value property of the CWButton ActiveX control, which is part of the National Instruments Measurement Studio User Interface ActiveX Library, when the temperature reaches 85 degrees Fahrenheit or higher.

In this case, the CWButton control acts as an LED, changes colors, and displays Warning when the temperature reaches the limit, which is the on state of the CWButton control.

Note  In this example, you could use the ActiveX Property Browser or property pages to set the OffText, OffColor, OnText, and OnColor properties for the CWButton control because you do not need to set those properties programmatically.

LabVIEW as an ActiveX Server

The LabVIEW application, VIs, and control properties and methods are available through ActiveX calls from other applications. Other ActiveX-enabled applications, such as Microsoft Excel, can request properties, methods, and individual VIs from LabVIEW, and LabVIEW acts as an ActiveX server.

For example, you can embed a VI graph in an Excel spreadsheet and, from the spreadsheet, enter data in the VI inputs and run the VI. When you run the VI, the data plot to the graph.

Refer to the labview\examples\comm\freqresp.xls for an example of using LabVIEW properties and methods in an Excel spreadsheet.

Support for Custom ActiveX Automation Interfaces

If you are writing an ActiveX client that accesses properties and methods from an ActiveX server using LabVIEW, you can access custom interfaces exposed by the server. You do not need to use IDispatch to do so. However, the developer of the ActiveX server must make sure the parameters of the properties and methods in these custom interfaces have Automation (IDispatch) data types. The developer of the server must do so to expose multiple interfaces from one object, rather than through multiple objects. You still can use the interfaces in the LabVIEW environment. Refer to your server development programming environment documentation for more information about accessing custom interfaces.

Using Constants to Set Parameters in ActiveX VIs

Some parameters in ActiveX nodes take a discrete list of valid values. Select the descriptive name in the ring constant to set these parameter values. To access the ring constant when building an ActiveX VI, right-click the parameter of the node that accepts data values and select CreateConstant from the shortcut menu. The selections available in the ring constant depend on the refnum passed to the node. The following block diagrams use ring and numeric constants to set parameter values.

Parameters that accept data values have a small arrow to the left of the parameter name. To view the corresponding numeric data value, right-click the ring constant and select Visible ItemsDigital Display from the shortcut menu.

The two previous block diagrams access the Microsoft Excel application and execute a method. The Index parameter of the ActivateMicrosoftApp method has the following options: MicrosoftWord, MicrosoftPowerPoint, MicrosoftMail, MicrosoftAccess, MicrosoftFoxPro, MicrosoftProject, and MicrosoftSchedulePlus.

To identify the numeric value of the Index parameter that corresponds to the MicrosoftAccess option in the first block diagram, select the MicrosoftAccess option from the pull-down menu in the ring constant. The numeric value of the currently selected option appears in a box next to the ring constant. Instead of using a ring constant, you can enter the numeric value of an option into a numeric constant, as shown in the second block diagram.

ActiveX Events

To use ActiveX events in an application, you must register for the event and handle the event when it occurs. ActiveX event registration is similar to dynamic event registration. However, the architecture of an ActiveX event VI is different than the architecture of an event-handling VI. The following components make up a typical ActiveX event VI:

  • ActiveX object for which you want to generate an event.
  • Register Event Callback function to specify and register for the type of event you want to generate.
  • Callback VI that contains the code you write to handle the event you specify.

You can generate and handle events on ActiveX objects in a container or on ActiveX objects you specify by using an Automation Refnum. For example, you can call a Windows tree control from an ActiveX container and specify that you want to generate a Double Click event for the items displayed in the tree control.

The Register Event Callback function is a growable node capable of handling multiple events, similar to the Register For Events function.

When you wire an ActiveX object reference to the Register Event Callback function and specify the event you want to generate for that object, you are registering the ActiveX object for that event. After you register for the event, create a callback VI that contains the code you write to handle the event. Different events may have different event data formats so changing the event after you create a callback VI might break wires on the block diagram. Select the event before you create the callback VI.

Loading VIs with an Updated ActiveX Type Library

When you load a VI with a change in an ActiveX Type Library's major version, LabVIEW launches a warning dialog box, informing you of the change. When you load a VI with a change in an ActiveX Type Library's minor version or time stamp, the VI, once loaded, includes an asterisk in its title bar and in the list of open VIs displayed in the Window menu. When you save the VI, the asterisk disappears until you make a new change.


Resources

WAS THIS ARTICLE HELPFUL?

Not Helpful