03-25-2010 11:29 PM
Hi there,
I am writing an application that is passing a simple cluster of doubles and an int from a C++ DLL to LV. I have used the Call_DLL.vi as reference. The values getting returned in the cluster are not the same as those returned to LV using a bunch of get() routines.
Here is the C code that uses the structure:
typedef struct {
double Distance; /* Distance measured in millimeters */
int BitSet; /* Measurement error flag, as follows:0 = no error
2 = too close to target or bad signal
4 = too far from target or signal is too noisy
FF = unknown */
double XPos;double YPos;
double ZPos;double RotMat11;
double RotMat12;double RotMat13;
double RotMat21;double RotMat22;
double RotMat23;double RotMat31;
double RotMat32; double RotMat33;} Data;
_declspec(dllexport) int System_Single_Measurement(Data *Input, Data *Return_Struct){
Return_Struct->Distance = Measure.Distance;
Return_Struct->BitSet = (int)Measure.BitSet;
//does stuff to fill the Postion[] and RotMatrix[] arrays.
Return_Struct->XPos = Position[0];
Return_Struct->YPos = Position[1];
Return_Struct->ZPos = Position[2];
Return_Struct->RotMat11 = RotMatrix[0][0];
Return_Struct->RotMat12 =RotMatrix[0][1];
Return_Struct->RotMat13 = RotMatrix[0][2];
Return_Struct->RotMat21 = RotMatrix[1][0];
Return_Struct->RotMat22 = RotMatrix[1][1];
Return_Struct->RotMat23 = RotMatrix[1][2];
Return_Struct->RotMat31 = RotMatrix[2][0];
Return_Struct->RotMat32 = RotMatrix[2][1];
Return_Struct->RotMat33 = RotMatrix[2][2];
return 1;}
An example of a get() routine:
_declspec(dllexport) double Camera_GetXPosition(){return Position[0];
}
I have attached the VI we are using as well.
It is possible that there is some weird glitch in the rest of the C code, but since the values returned by the get() methods are correct, it seems likely that I have messed up returning the cluster.
Thanks!
03-26-2010 04:34 AM - edited 03-26-2010 04:35 AM
At the first try to add #pragma pack(1) before struct typedef. I'm not sure which defaults are used by your compiler, but you may have 4 bytes gap between int BitSet and double XPos members.
If you can't change your C code, then try to insert "int Dummy " between int BitSet and double XPos.
Andrey.