Problems with struct pointer pointer in calllib

8 次查看(过去 30 天)
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
Jim Hokanson 2014-3-31
@Friedrich,
I should clarify, the input to the second function is the numerical result of unused from the first. There is however an additional level of redirection that I'm not quite sure that I'm handling correctly. Something like:
A => points to => B => points to => C (which is a structure)
A : ADI_FileHandle*
B : ADI_FileHandle == typedef struct ADI_FileHandle__ *ADI_FileHandle
C : ADI_FileHandle__
I think what I am passing to the second function is C (ADI_FileHandle__), not ADI_FileHandle (Notice the missing trailing underscores)
I'm giving the mex a shot now ...
Jim Hokanson
Jim Hokanson 2014-3-31
Well, after many hours of making silly mistakes in mex, the code works just fine (in mex). I think the problem is the inability to get the double pointer on the structure working as intended.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call C from MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by