什么是Matlab的相当于空的,当它调用COM / ActiveX方法? [英] What's the Matlab equivalent of NULL, when it's calling COM/ActiveX methods?

查看:187
本文介绍了什么是Matlab的相当于空的,当它调用COM / ActiveX方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我维护它可以通过COM实现自动化的程序。一般客户使用VBS做自己的脚本,但我们有一对夫妇谁使用 Matlab的ActiveX支持的和有麻烦的调用带有null参数的COM对象的方法的客户。

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.

他们已经问过他们是如何做到这一点在Matlab - 我一直在淘<一个href=\"http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/bq4epvg-1.html\">Mathworks'的COM / ActiveX文档了一天左右,现在并不能看着办吧。

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.

他们的榜样code可能是这个样子:

Their example code might look something like this:

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

其中, NULL 是另一种语言,我们会写 NULL 没有,或者,当然,传递一个对象。问题是,这是可选的(而这些在大多数可选参数实现的,但不是所有,例) - 这些方法期望得到NULL经常

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.

他们告诉我,他们一直试图 [] (从我的阅读似乎是最有可能的),以及没有 0 。我不知道有多少是有效的,甚至Matlab的关键字 - 在这种情况下肯定没有工作

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.

谁能帮助?什么是Matlab的语法用作COM方法参数空指针/对象?

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

更新:感谢到目前为止,所有的答复!不幸的是,没有一个答案似乎工作,甚至没有 libpointer 。该错误是在所有情况下相同的:

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:

错误:类型不匹配,参数2

这个参数在COM类型库中RIDL被描述为:

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);

有问题的组件类实现一个单一的接口的IDispatch从下降。

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

推荐答案

我在这里回答我的问题,谈论Matlab的技术支持后:有没有没有<当量/ code>,和Matlab不支持这一点。

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.

在详细点:Matlab不支持可选参数,但不支持传递变种NULL指针(实际上,遵循究竟如何VB的没有的作品,一个 VT_EMPTY 的变体,我认为)是否作为可选参数或没有。还有一些空/ pointerish类型,其中很多在我的问题还是在各种答案中提到的文件,但这些似乎并没有成为可用其COM支持。

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.

他们给我用他们创造了一个COM DLL和Excel来创建可以在脚本中被传递的虚拟对象没有用Matlab支持的解决方法。我还没有设法让这种解决方法/破解工作,即使我有不幸的是我,也可能无法重新分配。但是,如果遇到同样的问题,这说明可能会给你一个起点,至少!

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!

这是可能这个旧的新的博客文章可能的有关。 (我不再能够访问有问题的源$ C ​​$ c或访问Matlab的工作,刷新我的记忆中或进行测试。)

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.)

简言之,对于的IUnknown (或派生)的参数,你需要为他们 [唯一] 属性合法为 NULL 。上面的声明需要Matlab的创建或通过在 VT_EMPTY 变种,它不能做。也许添加[唯一]可能促使Matlab引擎在 NULL 指针传递(或含变种a NULL 指针),而是 - 假定它是能够做到这一点,这是猜测

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.

这都是猜测,因为这code和它的复杂性是几年我身后的这一点。不过,我希望它能帮助任何未来的读者。

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.

这篇关于什么是Matlab的相当于空的,当它调用COM / ActiveX方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆