03-15-2011 09:37 AM
Can anyone tell me how to get the data passed through void *callbackData?
The code below, panel_ptr has the correct address but always contains zero.
void CVICALLBACK value_changed (void *callbackData)
{
int* panel_ptr;
panel_ptr = callbackData;
calculate_new_value (*panel_ptr);
}
int panel;
panel = 2;
PostDelayedCall (value_changed, &panel, 0.2);
Solved! Go to Solution.
03-15-2011 10:04 AM - edited 03-15-2011 10:05 AM
The problem in using callbackData parameter is that if it is a pointer, it must be a pointer to something that is still valid at the moment the callback executes. That is to say, you cannot pass the pointer to a local variable in callbackData since when the callback executes the pointer is no more valid. You can pass its value, instead, this way:
...SomeFunction ( )
{
int panel;
...
panel = 2;
PostDelayedCall (value_changed, (void *)panel, 0.2);
...
}
void CVICALLBACK value_changed (void *callbackData)
{
int panel_ptr;
panel_ptr = (int)callbackData;
calculate_new_value (panel_ptr);
return;
}
There are a lot of discussions on the forums about callbackData parameter that you may wnat to read.