Handle class via mwArray in C++

2 views (last 30 days)
Ulrich
Ulrich on 13 May 2019
Commented: Ulrich on 13 May 2019
Hello,
i am using Matlab code (compiled to a .dll) that creates an object of a handle class. Methods of the Object can be called by using the .dll interface functions. However, methods are not called directly but by using "wrapper functions" which accept a HANDLE to the MATLAB object as input.
The methods can be called directly in MATLAB and as described "indirectly" from C++, but they return different results when i call them from C++.
What can be the cause for such behaviour?
I would be glad to have any hint, why MATLAB code can behave different when called through a .dll.
Thanks a lot,
Ulrich
  1 Comment
Ulrich
Ulrich on 13 May 2019
Example below:
classdef handleExample < handle
% ....
methods
function obj = handleExample(input)
% create Obj
end
function obj = doSomeThing(obj, input)
% ... lots of things
%
end
end
end
The constructor is then called in function which returns this "Handle":
function hOut = mwConstructor()
% ...
input = struct( 'a lot of fields', '');
hOut = handleExample(input);
return;
end
This function is added to the .dll exported functions as well as a wrapper:
function ret = wrapper(hObj, input)
%
hObj = doSomeThing(hObj, input)
ret = hObj.special_field;
return;
end
The wrapper is then called cyclic by a C++ application that makes use of the .dll that was generated by the MATLAB compiler.
But the results of "doSomeThings" seem to differ not just slightly, but in a really crazy way.

Sign in to comment.

Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!