LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can a callback call another callback function?

When an event calls my callback function it uses another callback function. So instead of re-doing the code, I did a raw "C" call of the 2nd callback function. However, the 2nd callback function was never called.

In example below, do_more_stuff() was never entered, but do_stuff() and do_other_stuff() was called. What is wrong with my code?

Example:
button press 1 -> callback function callback1().
button press 2 -> callback function callback2().

int CVICALLBACK callback2(
int panel, int control, int event,
void *callback_data, int data1, int data2 )
{
if (event == EVENT_COMMIT)
{
do_more_stuff();
// we dont use PANEL, CONTROL, so hardcoding (0,0)
// is valid
}
} // end
callback2

int CVICALLBACK callback1(
int panel, int control, int event,
void *callback_data, int data1, int data2 )
{
if (event == EVENT_COMMIT)
{
do_stuff();
callback2(0,0,EVENT_COMMIT,0,0,0);
do_other_stuff();
}
return 0;
} // end callback1
0 Kudos
Message 1 of 3
(2,780 Views)
I use this method in my code without a problem - in fact try replacing do_stuff with printf's - it works fine!

int CVICALLBACK callback2(int panel, int control, int event,
void *callback_data, int data1, int data2 )
{
if (event == EVENT_COMMIT)
{
/* See if we were called with panel == 0 */
if (panel)
{
/* We were called from button press */
printf("Call Back 2\n");
}
else
{
/* We were called from callback1 */
printf("SUCCESS!\n");
}
}
return 0;
} // end callback2


int CVICALLBACK callback1(int panel, int control, int event,
void *callback_data, int data1, int data2 )
{
if (event == EVENT_COMMIT)

{
printf("Call Back 1 - Running Callback 2... ");
callback2(0,0,EVENT_COMMIT,0,0,0);
}
return 0;
} // end callback1"


Yeilds:
Press Button1 (callback1):
Call Back 1 - Running Callback 2... SUCCESS!

Press Button2 (callback2):
Call Back 2

There isn't a goto somewhere is there?!
Message 2 of 3
(2,780 Views)
Thanks for looking at this. I tried and tried to duplicate it without using my actual code, and I got the same response as you did.
- then I traced my code again to see if I needed to send my entire project to the forum. But I found out that my param list was incorrect:
Callback(0, EVENT_COMMIT, 0,0,0,0 )
the optical illusion got me!

Thanks for the help!
0 Kudos
Message 3 of 3
(2,780 Views)