从com对象返回数组 [英] return array from com object

查看:223
本文介绍了从com对象返回数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个报警名称的列表从COM传递到ASP页面中使用的VBScript。如果方法名为 GetAlarms ,那么方法的签名是什么?由 GetAlarms 返回的警报数量会有所不同。

I want to pass a list of alarm names from COM to VBScript used in ASP pages. If the method name is GetAlarms, What would be the signature of the method?. The number of alarms returned by GetAlarms will vary.

VBScrip是否支持安全阵列?

Does VBScrip support Safe Array?

推荐答案

* .idl文件中的声明如下所示:

The declaration in the *.idl file would look like this:

[id(1)] HRESULT GetAlarms([out,retval] SAFEARRAY(VARIANT)* pAlarms);

对应的C ++方法如下所示:

The corresponding C++ method would look like this:

STDMETHODIMP CMyClass::GetAlarms(SAFEARRAY** pAlarms)
{
    CComSafeArray<VARIANT> alarms(3);
    CComVariant value;

    value = L"First Alarm";
    alarms.SetAt(0, value);

    value = L"Second Alarm";
    alarms.SetAt(1, value);

    value = L"Third Alarm";
    alarms.SetAt(2, value);

    *pAlarms = alarms.Detach();

    return S_OK;
}



最后,这里是一个使用上述方法的示例VBScript: p>

And finally, here is a sample VBScript that uses the above method:

Set obj = CreateObject("MyLib.MyClass")
a = obj.GetAlarms
For i = 0 To UBound(a)
   MsgBox a(i)
Next



<当然,你会使用别的东西,而不是 MsgBox

这篇关于从com对象返回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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