Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
This Document is not yet Rated  Rate this Document

What Does the Return Value of a LabWindows/CVI Callback Function Do?

Primary Software: LabWindows/CVI Development Systems>>Full Development System
Primary Software Version: 8.5.1
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
I noticed that by default my CVI Callback Functions for User Interface events return 0. What are the different options for the return value and what do they do?

Solution:
A CVI User Interface (UI) callback function gets called whenever there is an event on the UI component and you generally use a switch statement to handle the different events. The function is called for every single event that happens on that UI component whether or not you have any code to handle that event.

You can modify this behavior by changing the return value of the callback function.

According to the CVI Help:
User callbacks must always return 0 unless they intend to swallow the event to which they are responding. To swallow the event, the callback should return 1.

Return Value Behavior
0 Default
1 Swallow Event

For instance, clicking on a Command Button in CVI normally generates multiple events, EVENT_LEFT_CLICK and EVENT_COMMIT among others.
However, if you return 1 from the callback function for the EVENT_LEFT_CLICK event, the callback function is not called a second time for the EVENT_COMMIT event.
The attached example program demonstrates this behavior.

One thing to keep in mind however, is that not all events are swallowable. The CVI Help lists the events that are swallowable.



Related Links:
KnowledgeBase 2619O5XL: Why Do Callbacks Get Called More Than Once?
LabWindows/CVI 8.5 Help: Swallowing Events



Attachments:
Swallowing Events.zip




Report Date: 05/07/2008
Last Updated: 05/09/2008
Document ID: 4L6AR9PE

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit