How can I make a struct pointer in Matlab to pass as an argument to a function in a C dll?

14 views (last 30 days)
Hi,
I have a C dll with a function like below:
void FunctionName ( StructName * Struct_Instance, uint8_t var1)
How can I make a struct pointer (StructName * ) in matlab to pass to this function?
I have tried doing something like this but I get errors:
S.Dev_ID = 5;
S.Fs = 3;
Sp = libpointer('c_struct',S);

Answers (1)

Sugandhi
Sugandhi on 16 Feb 2023
Hi,
I understand that you were trying to pass struct pointer in MATLAB to a function in C DLL.
The shared library interface supports all standard scalar C types. Equivalent MATLAB types for C types can be found here- https://www.mathworks.com/help/matlab/matlab_external/passing-arguments-to-shared-library-functions.html
Some C arguments (for example, **double, or predefined structures), are different from standard MATLAB types. In these cases, either pass a standard MATLAB type and let MATLAB convert it for you or convert the data yourself using the MATLAB functions libstruct and libpointer.
For more information on manually converting data passed to functions, see the following link:
To Convert MATLAB structure to C style structure for use with shared C library, you can try using libstruct function.
For more information on libstruct and libpointer functions kindly go through following links –

Products

Community Treasure Hunt

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

Start Hunting!