LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing value from a Callback function from another file

Solved!
Go to solution

Within in a main.c i am having a CallBack function , where  get the current value of a control.

GetCtrlVal (panelHandle, PANEL_RINGSLIDE_1, &p);

 

I am having another  file ( test.c) in the same folder. I need to use the value of &p in that test.c file. How is that possible??

 

I though of including #include main.c in the test.c file but did not work.

Any ideas?

 

 

 

 

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 1 of 3
(3,476 Views)
Solution
Accepted by Nghtcrwlr

In applications that use more than one source file, it is good practice to have a common set of definitions that covers your entire project. So, for example, you could have a file "common.h", which is #include'd by both your main.c and test.c files. In that common.h file, you could have a statement:

 

    extern int p;

 

This tells the compiler, for each of your c file compilation steps, that the variable p is defined somewhere else and not to worry about it. Now in just one of your .c files (it does not really matter which one) you then need to declare the actual variable p:

 

    int p;

 

So now when you refer to p in any of your modules, you are referring to the same variable across the entire project. (It is probably best to use a longer, more descriptive name for the variable instead of just p - this will avoid possible confusion as your program grows in complexity.)

 

JR

Message 2 of 3
(3,461 Views)

I created a seperate file named "common.h" with following codes:

extern int period;
extern int amplitude;

 

 

I also included this common.h in both main.c and test.c

 

#include "common.h"

 

But theb i get these errors:

 

2 Project link errors:


 Undefined symbol '_amplitude' referenced in "generate.c".
 Undefined symbol '_period' referenced in "generate.c".

 

--------------------------------------------

oops.. now i found out theproblem. I had defined the variables period and amplitude inside the main. Now when i took them outside the main, it worked. Yes i guess it is better to create a common file like "common.h" when you work with several variables several times.

 

thank ypu very much  jr_2005..

 

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 3 of 3
(3,453 Views)