Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the Matlab equivalent of NULL, when it's calling COM/ActiveX methods?

I maintain a program which can be automated via COM. Generally customers use VBS to do their scripting, but we have a couple of customers who use Matlab's ActiveX support and are having trouble calling COM object methods with a NULL parameter.

They've asked how they do this in Matlab - and I've been scouring Mathworks' COM/ActiveX documentation for a day or so now and can't figure it out.

Their example code might look something like this:

function do_something()
   OurAppInstance = actxserver('Foo.Application');
   OurAppInstance.Method('Hello', NULL)
end

where NULL is where in another language, we'd write NULL or nil or Nothing, or, of course, pass in an object. The problem is this is optional (and these are implemented as optional parameters in most, but not all, cases) - these methods expect to get NULL quite often.

They tell me they've tried [] (which from my reading seemed the most likely) as well as '', Nothing, 'Nothing', None, Null, and 0. I have no idea how many of those are even valid Matlab keywords - certainly none work in this case.

Can anyone help? What's Matlab's syntax for a null pointer / object for use as a COM method parameter?

Update: Thanks for all the replies so far! Unfortunately, none of the answers seem to work, not even libpointer. The error is the same in all cases:

Error: Type mismatch, argument 2

This parameter in the COM type library is described in RIDL as:

    HRESULT _stdcall OurMethod([in] BSTR strParamOne, [in, optional] OurCoClass* oParamTwo, [out, retval] VARIANT_BOOL* bResult);

The coclass in question implements a single interface descending from IDispatch.

like image 526
David Avatar asked Feb 17 '10 04:02

David


People also ask

Is there a null in Matlab?

null (MATLAB Functions) Z = null(A) is an orthonormal basis for the null space of A obtained from the singular value decomposition. That is, A*Z has negligible elements, size(Z,2) is the nullity of A , and Z'*Z = I .

WHAT IS NULL value in Matlab?

null(A) calculates the singular value decomposition of matrix A , such that A = U*S*V' . The columns of V corresponding to singular values equal to zero (within tolerance) form a set of orthonormal basis vectors for the null space.

What does NULL function do in Matlab?

example. Z = null( A ) returns a list of vectors that form the basis for the null space of a matrix A . The product A*Z is zero. size(Z, 2) is the nullity of A . If A has full rank, Z is empty.


2 Answers

I'm answering my own question here, after talking to Matlab tech support: There is no equivalent of Nothing, and Matlab does not support this.

In detail: Matlab does support optional arguments, but does not support passing in variant NULL pointers (actually, to follow exactly how VB's Nothing works, a VT_EMPTY variant, I think) whether as an optional argument or not. There is documentation about some null / pointerish types, a lot of which is mentioned in my question or in various answers, but these don't seem to be useable with their COM support.

I was given a workaround by Matlab support using a COM DLL they created and Excel to create a dummy nothing object that could be passed around in scripts. I haven't managed to get this workaround / hack working, and even if I had unfortunately I probably could not redistribute it. However, if you encounter the same problem this description might give you a starting point at least!

Edit

It is possible this Old New Thing blog post may be related. (I no longer work with access to the problematic source code, or access to Matlab, to refresh my memory or to test.)

Briefly, for IUnknown (or derived) parameters, you need a [unique] attribute for them to legally be NULL. The above declaration required Matlab create or pass in a VT_EMPTY variant, which it couldn't do. Perhaps adding [unique] may have prompted the Matlab engine to pass in a NULL pointer (or variant containing a NULL pointer), instead - assuming it was able to do that, which is guesswork.

This is all speculation since this code and the intricacies of it are several years behind me at this point. However, I hope it helps any future reader.

like image 138
David Avatar answered Sep 21 '22 11:09

David


From the mathworks documentation, you can use the libpointer function:

p = libpointer;

and then p will be a NULL pointer. See that page for more details.

See also: more information about libpointer.

like image 34
Peter Avatar answered Sep 22 '22 11:09

Peter