cancel
Showing results for 
Search instead for 
Did you mean: 

pass data back through the (void*)callback

ray123
Member

pass data back through the (void*)callback

I'd like to pass data back through the (void*) callback data variable to the calling function without using global variables.  Could you please show me sample code which assigns a value to the *callback data  (within the callback) thus allowing it to be passed back to the calling function
2 REPLIES 2
JonathanN
NI Employee (retired)

Re: pass data back through the (void*)callback

Message contains a hyperlink
Hi ray123,
 
Check out the Using the void *callbackData Parameter in Callback Functions KnowledgeBase and the Callback Data Example in CVI example for help. Basically you will be using the SetCtrlAttribute function with the ATTR_CALLBACK_DATA attribute which will allow you to assign the callback data pointer to some user data.
 
Hope this helps!
 
Best Regards,
Jonathan N.
National Instruments
Highlighted
Guillaume Dargaud
Active Participant

Re: pass data back through the (void*)callback

I often use it to pass single integers without using pointer logic.

In the calling code:
PostDeferredCall(cb_ReceivedControl, (void*)(Card<<8 | usbData[0]));

In the receiving code:
static void CVICALLBACK cb_ReceivedControl(void *callbackData) {
int Card=(int)callbackData>>8;
char Data=(int)callbackData&0xFF;
....}

--
Guillaume Dargaud
http://www.gdargaud.net/