LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

using PostDelayedCall how do I get the value passed through void *callbackData?

Solved!
Go to solution

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);

0 Kudos
Message 1 of 2
(2,790 Views)
Solution
Accepted by topic author JPS_CSE

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(2,784 Views)