12-10-2009 03:04 AM
ok I have a situation using extern.
basically im calling declaring my handle as a parameter in one file, and im calling that particular function in another file.
so my question how would i declare the handle as a extern if its parameter to keep the same value . this is how im calling it in the second file below.
*****************************************
int Initialize_AutoEOD_DAS(void)
{
int iStatusCheck=0;
int iDAS300_Handle=0;
HRESULT hStatusResult=0;
ERRORINFO usComError={0};
CAObjHandle hAppObj=0;///////////////////////this particular handle right here how do it declare as a extern to keep its value?
iStatusCheck=Move_Gimbals_To_Center ();
if(iStatusCheck<SUCCESS)
{
return FAILURE;
}
Connect_Auto_Eod_Software(iDAS300_Handle,
hStatusResult,
hAppObj,
usComError
);
Initialize_DAS3000_Software(hStatusResult,
usComError,
hAppObj
);
Wait_For_Complete_Init_Of_AutoEOD(hStatusResult,
usComError,
hAppObj);
but in the key file where i need to call it as a extern how would i do that?
int Configure_Frame_Grabs(int iSelectNumOfFrames,
int iDAS300_Handle,
HRESULT hResultChk,
ERRORINFO usComError,
CAObjHandle hAppObj);
*************************************************************
12-10-2009 03:17 AM
By making an object extern, you are of course giving it global scope within your program. So it does not make sense to then try to have it declared as a local within a function. Follow the general approach that was discussed in a previous thread on this topic, and make sure that the one source file that contains the actual declaration of the variable does so at the top module level, outside of any functions. (Otherwise you will get a different local variable of the same name...)
JR
12-10-2009 03:45 AM
im a little confused, let me try to translate.
so my question is the second file delcared it as global.
so are you saying keep the handle global instead of passing it as a parameter in a function in the second file.
so if i pass the object handle as a parameter, do i need to extern it ?
right now i have the object handle in a parameter, which i cant extern it to keep it value going over in the next file
12-10-2009 05:39 AM
In your common header file, add the following line:
extern CAObjHandle hAppObj;
In the first file, add the following line at the top level of the module:
CAObjHandle hAppObj = 0;
In the first file, change your function as follows:
int Initialize_AutoEOD_DAS(void)
{
int iStatusCheck=0;
int iDAS300_Handle=0;
HRESULT hStatusResult=0;
ERRORINFO usComError={0};
//CAObjHandle hAppObj=0; // This is now declared as a global, so you don't want to redeclare it here
iStatusCheck=Move_Gimbals_To_Center ();
...
In the second file, change your function as follows:
int Configure_Frame_Grabs(int iSelectNumOfFrames,
int iDAS300_Handle,
HRESULT hResultChk,
ERRORINFO usComError,
//CAObjHandle hAppObj // Already exists as a global, so don't need it here
);
JR
12-10-2009 02:36 PM
this is how i already have it, but my company dont want nothing global so how would i pass it as a parameter without break the scope already,
should i create a function get the return value of the handle?
int Get_Handle(void)12-11-2009 05:47 AM
darnell wrote:...my company dont want nothing global...
It would have been useful if you had mentioned that in your first post...
OK, so, despite the subject title of extern, you are looking for a multi-file solution that does NOT use externs. Here's one idea. Create a new c source file, with contents along the following lines:
static int int1; // Although at the top level, static confines it to this module only
void SetInt (int param1) {
int1 = param1; // Copy the parameter to our private variable
}
int GetInt (void) {
return int1; // Return our private variable to anyone who wants it
}
Create a new header file to match:
void SetInt (int param1) ;
int GetInt (void) ;
In all your source files which need acces to the variable, #include this header file. Then you can just call the two functions to write/read the variable, from any of the source files. I've used ints in the above example - obviously you can modify the code to use different variable types as required.
JR
12-11-2009 06:59 AM
sorry about that just getting back , yea me and you are on the same page, thats what i discover to do at the last minute yesterday when i sent you the last post, do a set and a get, I declared static global at the top of the file.
thanks again.