Problems with struct pointer pointer in calllib
이전 댓글 표시
I'm working with a header that has the following declaration:
struct ADI_FileHandle__ { int unused; }; typedef struct ADI_FileHandle__ *ADI_FileHandle;
One function I am using is:
DLLEXPORT ADIResultCode ADI_OpenFile(const unsigned short* path, ADI_FileHandle* fileH, ADIFileOpenMode mode);
My Matlab code calling this is:
result = calllib('ADIDatIOWin','ADI_OpenFile',int16(file_path),file_handle_pointer,file_open_mode);
This results in a value for unused (structure field in ADI_FileHandle__ ). A typical value is something like 1654585380. The result value indicates a success.
I then try to call another function:
DLLEXPORT ADIResultCode ADI_GetNumberOfChannels(ADI_FileHandle fileH, long* nChannels);
in Matlab as:
file_handle_pointer = libpointer('ADI_FileHandle__Ptr');
set(file_handle_pointer,'Value',struct('unused',int32(1654585380)))
n_channels_pointer = libpointer('longPtr');
result = calllib('ADIDatIOWin','ADI_GetNumberOfChannels',file_handle_pointer,n_channels_pointer);
At this point Matlab crashes.
What am I missing?
Thanks, Jim
댓글 수: 5
Jim Hokanson
2014년 3월 31일
Kaustubha Govind
2014년 3월 31일
Sorry, I mistakenly created an answer (and deleted it), after realizing that you do follow the documentation: http://www.mathworks.com/help/matlab/matlab_external/working-with-pointers.html#f50712
Friedrich
2014년 3월 31일
Are you sure the DLL can handle a made up file_handle_pointer? I would assume it crashes because no actual valid file was opened and hence the DLL crashes.
Have you tried calling the ADI_GetNumberOfChannels function from a plain C application with the exact same inputs?
Jim Hokanson
2014년 3월 31일
Jim Hokanson
2014년 3월 31일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Call C from MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!