Matlab incorrectly reading in pointers

조회 수: 6 (최근 30일)
AlphaDecay
AlphaDecay 2020년 10월 23일
편집: AlphaDecay 2020년 10월 23일
I'm developing a C DLL and some Matlab code to interface with that DLL. The short version of it is that the DLL takes in a C struct pointer (struct *OD_INPUT) and returns a C struct pointer (struct *OD_OUTPUT).
The definition of the output is:
struct OD_OUTPUT {
double array1D[6];
double array2D[6][6];
double *Array1D_Pointer1;
double *Array1D_Pointer2;
int numEntries;
};
I'm using a lot of print statements throughout the DLL to confirm the input is being passed in correctly and that the output is being written correctly and everything seems to work fine up until the data gets returned to Matlab, where its read back into Matlab as what seems like unitialized values.
For example, array1D is supposed to contain 6 values of magnitude ~1000, but instead they're all magnitude ~10^(-315). Similarly, the int numEntries is supposed to be 13, but instead I get the return 1.57E9.
The final two lines of the DLL are:
print_dll_output(output); //Function for printing out all contets of the output struct
return &output;
and the print statement shows all the values as I expect them to be, so there's no chance for them to be changed before they're passed back to Matlab.
On the matlab side, I'm simply running:
odp = libpointer('OD_INPUT',odt); % creates a pointer to struct I want to pass to the DLL
od_out = calllib('castdll', 'od_call', odp, mat1, mat2, argv) % calls the dll
od_out.Value % print the value of the output pointed to be od_out
I'm omitting descriptions of the input because based on the print statements all the input is being read in correctly.
It seems to me that Matlab may be reading in the values in od_out with the wrong type, but I'm not sure how to force it to read it with a particular type. Any help would be appreciated

답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by