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

Registering and Handling .NET and ActiveX Events

LabVIEW 2013 Help

Edition Date: June 2013

Part Number: 371361K-01

»View Product Info

When handling a .NET or ActiveX event, you must register for the event (see steps 1 through 5) and then create a callback VI to handle that event (see steps 6 and 7).

Note Note  National Instruments recommends that you unregister for events when you no longer need to handle them using the Unregister For Events function. If you do not unregister for events, LabVIEW continues to generate and queue the events as long as the VI runs, even if no Event structure is waiting to handle them, which consumes memory and can hang the VI if you enable front panel locking for the events.

Complete the following steps to register and handle .NET and ActiveX events in LabVIEW.

  1. Create a new control in a .NET container or an ActiveX container. You also can use the Constructor Node to create a .NET object or use the Automation Refnum to call an ActiveX object from LabVIEW.
  2. Add the Register Event Callback function to the block diagram.

  3. Wire the reference or object to the Event input of the Register Event Callback function.
  4. Click the down arrow next to the Event input on the Register Event Callback function and select an event from the shortcut menu.
  5. (Optional) Wire the data that you want to pass to the callback VI to the User Parameter input. You can wire any LabVIEW data type, including a cluster, to this parameter.
  6. Right-click the VI Ref input and select Create Callback VI from the shortcut menu. LabVIEW creates a VI based on the event you select and the data you wire to the User Parameter. LabVIEW wires the callback VI to the VI Ref input.
Note  You can use an existing VI as a callback VI as long as the connector pane of the VI you intend to use matches the connector pane of the event data. The callback VI must be reentrant, and the reference to the callback VI must be strictly typed.
  1. Open the callback VI and edit the block diagram to handle the event. The callback VI contains the following elements:
    • Event Common Data contains the following elements:
      • Event Source is a numeric control that specifies the source of the event, such as LabVIEW, .NET, or ActiveX. A value of 1 indicates an ActiveX event. A value of 2 indicates a .NET event.
      • Event Type specifies which event occurred. This is an enumerated type for user interface events and a 32-bit unsigned integer type for .NET, ActiveX, and other event sources. For .NET and ActiveX events, the event type represents the method code, or ID, for the event registered.
      • Time Stamp is the time stamp in milliseconds that specifies when the event was generated.
    • Control Ref is a reference to the .NET or ActiveX object or the Automation Refnum on which the event occurred.
    • Event Data is a cluster of the parameters specific to the event the callback VI handles. LabVIEW determines the appropriate Event Data when you select an event from the Register Event Callback function. If an event does not have any data associated with it, LabVIEW does not create this control in the callback VI.
    • Event Data Out is a cluster of the modifiable parameters specific to the event the callback VI handles. This element is available only if the event has output parameters.
    • (Optional) User Parameter is data that you want to pass to the callback VI when the .NET or ActiveX object generates the event.
    Note Note  LabVIEW does not wire the Event Data input to the Event Data Out output automatically. Therefore, if you want to pass any part of the Event Data input through the callback VI, you must wire the Event Data input to the Event Data Out output manually.

 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit