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

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

问题描述

我维护一个可以通过COM自动化的程序。一般来说,客户使用VBS来完成他们的脚本,但是我们有几个客户使用 Matlab的ActiveX支持,并且遇到麻烦使用NULL参数调用COM对象方法 p>

他们问他们如何在Matlab中做这件事 - 我一直在冲刷 Mathworks的COM / ActiveX文档大约一天左右,不能弄清楚。



它们的示例代码可能如下所示:

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

code> NULL 在另一种语言中,我们写 NULL nil Nothing ,或者,当然,传入一个对象。问题是这是可选的(并且这些在大多数情况下作为可选参数实现,但不是所有情况) - 这些方法期望经常得到NULL。



他们告诉我他们试过 [] (从我的阅读看起来最可能)以及'' code>,没有'没有' c>, Null 0 。我不知道有多少是甚至有效的Matlab关键字 - 当然没有在这种情况下工作。



任何人都可以帮助?什么是Matlab的空指针/对象用作COM方法参数的语法?



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



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



在RIDL中描述了COM类型库中的这个参数:

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

这个coclass实现了一个从IDispatch下降的单个接口。


<我在回答我自己的问题,在谈到Matlab技术支持后:没有等价的没有



详细说明:Matlab支持可选参数,但不支持传入变量NULL指针实际上,为了遵循VB的 Nothing 工作原理,一个 VT_EMPTY 变体,我认为)是否作为可选参数。有一些null / pointerish类型的文档,很多是在我的问题或在各种答案中提到,但这些似乎不能用于他们的COM支持。



我得到了一个解决方法,由Matlab支持使用他们创建的COM DLL和Excel创建一个无空的对象,可以在脚本中传递。我没有设法得到这个解决方法/ hack工作,即使我不幸,我可能无法重新分配它。



编辑



如果您遇到同样的问题,可以这个旧新闻博客帖子 可能相关。 (我不再使用访问有问题的源代码,或访问Matlab,刷新我的记忆或测试。)



简单来说,对于 IUnknown (或派生)参数,您需要一个 [unique] 属性,合法地为 NULL 。上面的声明需要Matlab创建或传递一个 VT_EMPTY 变体,它不能做。也许添加[unique]可能提示Matlab引擎传递一个 NULL 指针(或包含 NULL 指针的变量),而是 - 假设它能够做到这一点,这是猜测。



这是所有的猜测,因为这个代码和它的复杂性是几年后我在这里点。但是,我希望它有助于任何未来的读者。


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.

解决方案

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.

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

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