LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

user defined function in labwindow

Hi,

I wrote a function that is independent of any button and GUI. I need to call it many times from different callback functions. I have a prototype but the compile complains missing prototype. Anyone has any idea about the problem? Does LabWindow have some special requirement on user defined functions?

Thanks in advance for your attention and reply!

Yaguang Yang
0 Kudos
Message 1 of 4
(3,114 Views)
LabWindows CVI is an ANSI C compiler. There are no special requirements for function prototypes in CVI beyond that in ANSI C.
Where is your prototype?
If you call the function from multiple .c files, you need to put the prototype in a .h file, and #include that .h file in every .c file that calls it. If you call the function from only one .c file, you can put the prototype in a .h file and #include it or you can put the prototype directly in the .c file that calls it.
0 Kudos
Message 2 of 4
(3,113 Views)
Thanks for the reply. If LabWindow does not have some special requirement on user defined function, it is strange from what I have seen...

I have something similar to (not exact) the following scenario, DesiredPosition(...) is a callback function of a command button. When I build the code, the error message is missing prototype. I also tried to put
int goDesiredPosition();
in a .h file and #include .h in the .c file.


--------------------------------
int goDesiredPosition();

int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "myLabWindow.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
SetPanelAttribute(panelHandle, ATTR_TITLE, "Dragon Fly Project");
CmtScheduleThreadPoolFunction(DEFAULT_THREAD_POOL_HANDLE, displayParametersInPanel, NULL, &functionID);
RunUserInterface ();
DiscardPanel (panelHandle);
CmtWaitForThreadPoolFunctionCompletion(DEFAULT_THREAD_POOL_HANDLE, functionID, 0);
return 0;
}

int CVICALLBACK DesiredPosition (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
goDesiredPosition();
break;
case EVENT_RIGHT_CLICK:
break;
}
return 0;
}


int goDesiredPosition()
{
int myPosition=5;
}
--------------------------------
0 Kudos
Message 3 of 4
(3,105 Views)
Your prototype needs to declare passed parameters. If you're not passing anything, declare the parameter void.

int goDesiredPosition(void);

Then you'll get a warning that you're missing a return value. Since you declared goDesiredPosition to be an int, the compiler expects you to return an int.

int goDesiredPosition(void)
{
int myPosition=5;
return 0; // or whatever you want to return
}
0 Kudos
Message 4 of 4
(3,101 Views)