matlabcomsafearray

How to pass single element safearray to COM function in MATLAB


I have an out of process COM server which provides a function f with the following signature:

f = void f(handle, int32, SafeArray(int32), SafeArray(int32))

When I try

h = actxserver('Server.Object.1');
x0=int32([0 0]);
y0=int32([0 0]);
h.f(int32(0), x0, y0)

Everything works fine. But

h = actxserver('Server.Object.1');
x0=int32([0]);
y0=int32([0]);
h.f(int32(0), x0, y0)

Gives the error message

Error using COM.Server_Object_1/f
Error: Type mismatch, argument 2

Error in test (line 4)
h.f(int32(0), x0, y0)

I also tried the feature

feature('COM_SafeArraySingleDim', 0 or 1)

which had no effect. I have the feeling that it worked in some earlier version of MATLAB, but I am not sure. Currently I am using 2019b.

Any idea how to make this work?


Solution

  • According to Mathworks tech support, it is not possible. I ended up wrapping the function in a c++ mex file.