12-21-2009 12:54 AM
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 );
}
12-21-2009 01:49 AM - edited 12-21-2009 01:52 AM
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;
12-21-2009 01:59 AM
12-21-2009 02:02 AM
darnell wrote:
so this -> by reference?
This operator is to address individual elements of a struct known by reference.
12-21-2009 02:14 AM
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]);
12-21-2009 05:35 AM
12-21-2009 07:41 AM
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);
12-21-2009 07:46 AM
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.
12-21-2009 07:52 AM - edited 12-21-2009 07:53 AM
I don't understand what you are doing!
The framework should be:
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! *