취소
다음에 대한 결과 표시 
다음에 대한 검색 
다음을 의미합니까? 

Accessing value from a Callback function from another file

해결 완료!
솔루션으로 이동

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 포인트
1/3 메시지
3,592 조회수
솔루션
주제 작성자 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

2/3 메시지
3,577 조회수

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 포인트
3/3 메시지
3,569 조회수