Example Code

Calling a LabWindows™/CVI Callback Function within Another Callback Function

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabWindows/CVI

Code and Documents

Attachment

Description

This article explains how you can call the code from another callback function when inside a callback function.

For example, if there were two different buttons on the UIR file, button1 and button2, that were related to two callbacks, callback1 and callback2, how you could call the code from callback1 from a certain section of callback2, without the need to press button1.

How to Use

Two methods exist in order to achieve this result.

Option 1:

You can make a call to the callback1 function from within callback2, making sure to pass the event argument as an EVENT_COMMIT. Callback functions are standard C functions, so you can call them from other parts of your program.

See Callback Example.zip, attached to this document, for an example.

Option 2: 

Another way to do it is by using the CallCtrlCallback function.

This function is interesting as, if the control does not have any callback function, no error will be thrown. The function will simply do nothing.
This will also allow you to call callback functions of dynamically created controls.

Related Links

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

OSZAR »