How to return an array to javascript from activex control


I'm trying to add a function to an activeX control that will return an array of int to my javascript.

Can anyone help me accomplish that? I believe I need to use SafeArray

Some of my code:

BEGIN_DISPATCH_MAP(CVombaShotsCtrl, COleControl)
       DISP_FUNCTION(CVombaShotsCtrl, "test", test, VT_VARIANT, VTS_NONE)

VARIANT CVombaShotsCtrl::test()

return ??;
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gammaeAuthor Commented:

After much more fooling around, I can't accomplish anything. What I have now return an unknow data type in javascript:

BEGIN_DISPATCH_MAP(CVombaShotsCtrl, COleControl)
     DISP_FUNCTION(CVombaShotsCtrl, "test", test, VT_VARIANT , VTS_NONE)

VARIANT CVombaShotsCtrl::test()
    VARIANT vaResult;

    SAFEARRAYBOUND sabound[1];  
    BSTR bstr = NULL;    
    HRESULT hr;
    // Create an array of size 100
    sabound[0].cElements = 100;
    sabound[0].lLbound = 0;    
    psa = SafeArrayCreate(VT_BSTR, 1, sabound);
    // Fill each array element with the same string, "contents"
    bstr = SysAllocString(OLESTR("contents"));
    for (long i=0; i<100; i++)
        hr = SafeArrayPutElement(psa, &i, bstr);
        if (FAILED(hr))
            goto error;
    V_VT(&vaResult) = VT_ARRAY | VT_BSTR;
    V_ARRAY(&vaResult) = psa;    
    return vaResult;
I'm not sure of my ground here, but since no one else has commented, I'll stick my neck out.

Doesn't SAFEARRAY give you a VBArray rather than a regular array? I think you have to create a new VBArray with the returned data in your JScript and use the toArray method to get a reference to an array.

NB: This is IE specific.
gammaeAuthor Commented:
I tried that, however javascript won't accept the return value as a vbarray.

The best I have been able to do is return a string and use javascript split to build my array.
PAQed with points refunded (500)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.