LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call ?

How to call callback function from
the inside other callback function ?


I'd like this function:
// =============================
int CVICALLBACK Pomiary (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:

.......
......

break;
}
return 0;
}
// =============================

to call inside this function:
// =============================
void CVICALLBACK Pomiar (int menuBar, int menuItem, void *callbackData, int
panel)
{

PostDeferredCall (????????);

}
0 Kudos
Message 1 of 2
(2,915 Views)
You can call a control's callback simply typing its name and filling the arguments as needed. A more polite way could be to use the toolbox function
CallCtrlCallback (panel, control, event, eventData1, eventData2, &retVal);
which treats correctly the ChainCtrlCallback added to the control (if any...).

That way your code will look so:

void CVICALLBACK Pomiar (int menuBar, int menuItem, void *callbackData, int
panel)
{
// ... Other source code
Pomiary (panel, control, EVENT_COMMIT, NULL, 0, 0);
// ... Other source code
return;
}

You must fill correctly the event and eventData parameter if necessary (look in userint.h for predefined macros for callback events and the use of eventData for single events).

You can also pass the callbackData parameters o
f the menu callback to the control callback that way:
Pomiary (panel, control, event, callbackData, 0, 0);

If you need to use PostDeferredCallback, you must build a transit function, for example:

void CVICALLBACK Pomiar (int menuBar, int menuItem, void *callbackData, int
panel)
{
...
PostDeferredCall (DefFunc, 0);
}

The transit function will look as follows:

void CVICALLBACK DefFunc (void *callbackData)
{
Pomiary (panel, control, EVENT_COMMIT, callbackData, 0, 0);
}

In this case you must be careful to the panel handle of the postdeferredcall function: either it is stored in a global variable or you must pass it in the callbackData parameter (casting it to a void* type in the caller and back to an int in the transit function before using it).

And that's all.

Remember that that way the Pomiary function is treated AFTER the caller function (and ts callers if any) are completely processed.

Roberto


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?
Message 2 of 2
(2,915 Views)