?
Solved

How to return an array to javascript from activex control

Posted on 2006-04-21
5
Medium Priority
?
1,744 Views
Last Modified: 2011-10-03

Hi,

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 ??;
}
0
Comment
Question by:gammae
  • 2
4 Comments
 

Author Comment

by:gammae
ID: 16517568

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)
END_DISPATCH_MAP()

VARIANT CVombaShotsCtrl::test()
{
    VARIANT vaResult;
    VariantInit(&vaResult);

    SAFEARRAYBOUND sabound[1];  
    SAFEARRAY FAR* psa = NULL;
    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;
    }  
    SysFreeString(bstr);  
    V_VT(&vaResult) = VT_ARRAY | VT_BSTR;
    V_ARRAY(&vaResult) = psa;    
    return vaResult;
}
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 16544111
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.
0
 

Author Comment

by:gammae
ID: 16544175
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.
0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16732274
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question