0

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.

Does VBScrip support Safe Array?

6
  • @Maanu: Why is this tagged C++? In C++ you cannot return arrays from a function. Commented Jun 14, 2011 at 3:56
  • @Als Unless he means a SAFEARRAY. Commented Jun 14, 2011 at 3:59
  • @Als: We are writing the COM component in C++ Commented Jun 14, 2011 at 4:23
  • VBScript requires SAFEARRAY. Commented Jun 14, 2011 at 5:15
  • @Hans Passant: Can I get an example for this? Commented Jun 14, 2011 at 6:08

1 Answer 1

4

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

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

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

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

In ASP, of course, you would use something else instead of MsgBox.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.