LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

typrdef struct passing by reference

i need help with passing my typedef struct by reference instead by value, I never really did a pass by reference on a typedef struct  i use pass by reference on everything else 

 

I cut some some stuff out like my error handling, so that i fit the right amount of characters in the message.

typedef struct
{
  int WidthCoordinate;
  int HeightCoordinate;   
} FRAME_DETAILS;

 

int Set_Param_Capture_Centroid(int iFrames,FRAME_DETAILS FullFrameSize);///***************  im trying to pass my typedef struct by reference  instead of by value 

 

int Set_Param_Capture_Centroid(int iFrames,
                                FRAME_DETAILS iFullFrameSize)///***************  im trying to pass my typedef struct by reference  instead of by value 
{
     HRESULT hResultCheckStatus =0;
   
     //This function is getting the number of frames configured
    hResultCheckStatus=AutoEOD_ISetupSetDefaultParam(g_hAppObj,&g_usComError,iFrames);
     if(hResultCheckStatus!=SUCCESS)
     {
         return SUCCESS;
     }
    hResultCheckStatus=hrCheck(hResultStatus,__FUNCTION__ ", ISetupSetDefaultParam");
     if(hResultCheckStatus<SUCCESS)
     {
         return FAILURE;
     }
   
    if(g_hAppObj)
    {
        double dPosX = 0;
        double dPosY = 0;
        long lIntensity = 0;
        long lMean = 0;
        long iNewPosX=0;
        long iNewPosY=0;
         
      
        //Declaring and initializing framegrabber
        AutoEODType_AutoEODSensor sensor1 = AutoEODConst_AEOD_Sens_IR1;
      
        //Gets the full framesize
        //Trim size in half
         iNewPosX=iFullFrameSize.WidthCoordinate/2;///***************  im trying to pass my typedef struct by reference  instead of by value 
        iNewPosY=iFullFrameSize.HeightCoordinate/2;///***************  im trying to pass my typedef struct by reference  instead of by value 
      
        //Waiting for complete initialization of AutoEOD software
       Wait_For_Complete_Init_Of_AutoEOD();
         
        //This function receives a point and locates the nearest hot zone
        //which is assumed to be the centroid
        hResultCheckStatus = AutoEOD_ITest2MeasCentroidStart (g_hAppObj, &g_usComError, 1,
                                            iNewPosX,iNewPosY);
       hResultCheckStatus=hrCheck( hResultStatus, __FUNCTION__ ", ITest2MeasCentroidStart");
                               
        //This Functions gets the centroid results
       hResultCheckStatus=AutoEOD_ITest2MeasCentroidResults(g_hAppObj,
                                                                                                &g_usComError,
                                                                                                &sensor1,
                                                                                                &dPosX,
                                                                                                &dPosY,
                                                                                               &lIntensity,
                                                                                                &lMean);
         if(hResultCheckStatus<SUCCESS)
         {
             return FAILURE;
         }
       hResultCheckStatus=hrCheck( hResultStatus, __FUNCTION__", ITest2MeasCentroidResults");
                                
         
        //Calculates the x and y offsets and stores the values to a text file          
       hResultCheckStatus=Calculate_Off_Set_Centroid_Point( dPosX,
                                                                                            dPosY,
                                                                                            iFullFrameSize    ///***************  im trying to pass my typedef struct by reference  instead of by value                                                                                           );
}
 

0 Kudos
Message 1 of 9
(4,479 Views)

You should be able to pass a struct by reference by using a pointer to it in the function definition and and the indirect component selection operator '->' instead of the direct one (dot):

 

 

int Set_Param_Capture_Centroid (int iFrames, FRAME_DETAILS *FullFrameSize);

 

 

iNewPosX = iFullFrameSize->WidthCoordinate / 2;
iNewPosY = iFullFrameSize->HeightCoordinate / 2;

 

Message Edited by Roberto Bozzolo on 12-21-2009 08:52 AM


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 9
(4,476 Views)
so this  -> by reference?
0 Kudos
Message 3 of 9
(4,470 Views)

darnell wrote:
so this  -> by reference?

This operator is to address individual elements of a struct known by reference.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 9
(4,466 Views)

 this is the error im getting

 

 340, 36   Left operand of -> has incompatible type 'FRAME_DETAILS'.

 

             iCurrentFrame->WidthCoordinate=atoi(g_sInstrData[FRAMEWIDTH]);
             iCurrentFrame->HeightCoordinate=atoi(g_sInstrData[FRAMEHEIGHT]);
 

0 Kudos
Message 5 of 9
(4,464 Views)
Where and how is iCurrentFrame defined?


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 9
(4,449 Views)

typedef struct
{
  int WidthCoordinate;
  int HeightCoordinate;   
} FRAME_DETAILS;

 

ok this is the starting point with the struct.

 

\
 

this is how it is define         FRAME_DETAILS iCurrentFrame={0};

 

then i use it in this function below

 

long Send_DAS3000_Command(char *sCommand)

 

             iCurrentFrame.WidthCoordinate=atoi(g_sInstrData[FRAMEWIDTH]);
             iCurrentFrame.HeightCoordinate=atoi(g_sInstrData[FRAMEHEIGHT]);
             
           //Configure the frame count and capture the Centroid.
              //Within this function we are calculating x and y offsets
              iErrorFlag = Set_Param_Capture_Centroid(iNumOfFramesSelected,&iCurrentFrame);
 

0 Kudos
Message 7 of 9
(4,440 Views)

I cannot see a "->" operator in this code.

 

Are you sure this is the code that generated the error you sent before?

 

The struct is not passed into the Send_DAS3000_Command function by reference here, it looks like it is a global.

The code you sent looks irrelevant with your question. 

S. Eren BALCI
IMESTEK
0 Kudos
Message 8 of 9
(4,437 Views)

I don't understand what you are doing!

 

The framework should be:

  1. Define the structure somewere in your code
  2. Define a variable of type 'your structure' inside a function. Use it within that function with traditional '.' operator to address individual structure fields
  3. Pass a pointer to the structure to another function (this is normally done in order to get back some values from the called function in the structure variable)
  4. Use '->'  operator inside the second function to manipulate structure fields
  5. When the second function returns, you will have the new values available in the structure variable

From what you are saying it seems to me that you have defined your 'iCurrentFrame' variable as global to the project or at leas to the .c file (it is not defined withint Send_DAS3000_Command function where it is used). If this is the case, you do not need to pass this variable at all to any function, since all functions will see this variable and will be able to modify it. And you will always use normal '.' component selector.

 

If this is not true, please explain more clearly your environment.

 

 

 

* Edit: ebalci was faster and briefer than me! *

Message Edited by Roberto Bozzolo on 12-21-2009 02:53 PM


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 9
(4,436 Views)