LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

extern

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);
 

 

 *************************************************************

 

0 Kudos
Message 1 of 7
(4,123 Views)

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

0 Kudos
Message 2 of 7
(4,122 Views)

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

 

 

0 Kudos
Message 3 of 7
(4,115 Views)

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

0 Kudos
Message 4 of 7
(4,107 Views)

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)
{
    CAObjHandle hAObj=-1;

    if(hAppObj<0)
    {
       return FAILURE;
    }
    else
    {
       hAObj=hAppObj;
       return hAObj;
    }
}
0 Kudos
Message 5 of 7
(4,079 Views)

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

0 Kudos
Message 6 of 7
(4,060 Views)

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.

0 Kudos
Message 7 of 7
(4,053 Views)