Using mex and clibgen
Show older comments
When using a shared library in matlab, that uses structs as data types they will be included in the library definition as classes.
% Example C code
%
% ...
%
% struct dummy
% {
% ...
% };
%
% double doSomething(dummy* handle)
% {
% ...
% }
clibgen.generateLibraryDefinition('example.dll')
summary(defineexample)
% Console output:
% Class clib.example.dummy
%
% Constructors:
% clib.example.dummy()
% clib.example.dummy(clib.example.dummy)
%
% No Methods defined
% No Properties defined
%
% Functions
% double clib.example.doSomething(clib.example.dummy)
So MATLAB basically creates a matlab class in the well known style from the struct out of the dll.
Does anyone know how i get back to the original class/struct when calling a mex function?
Or even if you know how exactly matlab converts this struct to a class would be helpfull.
For example:
dummy could be a collection of user data contained in a struct. A pointer to an instance of that struct is passed to a function inside the dll. Of course there are no pointers in MATLAB so an instance of the newly created (handle?) class will be used as the argument to the function generated by clibgen.
When i now pass that instance of the matlab class to a mex function is there a way of retreiving the original type 'dummy' from the object of type clib.example.dummy?
1 Comment
Jonas Steiner
on 18 Feb 2022
Edited: Jonas Steiner
on 18 Feb 2022
Accepted Answer
More Answers (0)
Categories
Find more on Build MATLAB Interface to C++ Library in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!