code on passing array from MFC ActiveX to Jscript...

This is a discussion on code on passing array from MFC ActiveX to Jscript... within the Windows Programming forums, part of the Platform Specific Boards category; Code: asb.. // A VBArray value. asj = new VBArray( asb ).toArray();//The conversion translates the //multidimensional VBArray into a single ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    爱国者同盟Chinese Patriot League
    Posts
    2

    Lightbulb code on passing array from MFC ActiveX to Jscript...

    Code:
     
    asb.. // A VBArray value.
    
    asj = new VBArray( asb ).toArray();//The conversion translates the 
    //multidimensional VBArray into a single 
    //dimensional JScript array. 
    
    window.alert(asj[0]);
    window.alert(asj[1]);
    window.alert(asj[2]);
    
    window.alert(asj[3]);
    window.alert(asj[4]);
    window.alert(asj[5]);
    
    window.alert(asj[6]);
    window.alert(asj[7]);
    window.alert(asj[8]);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ^^in the idl^^
    Code:
    [ uuid(CB35E5F2-...) ]
    dispinterface IMyList
    {
    ...
    methods:
    [id(5), helpstring("方法getItem")] VARIANT getItem(IDispatch* jjj, LONG kkk);
    };
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ^^in The CPP^^
    Code:
    BEGIN_DISPATCH_MAP(CUFList, CListBox)
    ...
    DISP_FUNCTION_ID(CUFList, "getItem", dispidgetItem, getItem, VT_VARIANT, VTS_DISPATCH VTS_I4)
    END_DISPATCH_MAP()
    
    
    VARIANT CmYList::getItem(IDispatch* ooo, LONG iii)
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    
    USES_CONVERSION;
    
    HRESULT hr= S_OK;
    
    VARIANT * pGIV = new VARIANT;
    VariantInit(pGIV); // WARNING You must initialize *pVal before calling Detach
    
    // Create SafeArray of VARIANT BSTRs
    SAFEARRAY *pSA;
    SAFEARRAYBOUND aDim[1];
    aDim[0].lLbound= 0;
    aDim[0].cElements= 3;
    pSA= SafeArrayCreate(VT_VARIANT,1,aDim);
    
    if (pSA != NULL) {
    _variant_t vOut;
    CString strIII;
    long l =0; 
    
    GetText(iii,strIII); 
    vOut= A2W(strIII);
    if (hr= SafeArrayPutElement(pSA, &l, &vOut)) {
    SafeArrayDestroy(pSA); // does a deep destroy
    return * pGIV;
    }
    l++;
    
    strIII.Format("%d", (int)GetItemData(iii));
    vOut= A2W(strIII);
    if (hr= SafeArrayPutElement(pSA, &l, &vOut)) {
    SafeArrayDestroy(pSA); // does a deep destroy
    return * pGIV;
    }
    l++;
    
    strIII.Format("%d", (int)GetSel(iii));
    vOut= A2W(strIII);
    if (hr= SafeArrayPutElement(pSA, &l, &vOut)) {
    SafeArrayDestroy(pSA); // does a deep destroy
    return * pGIV;
    }
    }
    
    
    V_VT(pGIV)= VT_ARRAY | VT_VARIANT; //pVal->vt= VT_ARRAY | VT_VARIANT; // oleauto.h
    V_ARRAY(pGIV)= pSA; // (pSA may be null) //pVal->parray= pSA; // oleauto.h
    return * pGIV;
    }

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ^^IN THE H^^
    Code:
    enum 
    {
    dispidgetItem = 5L, ...
    };
    VARIANT getItem(IDispatch* ooo, LONG iii);

  2. #2
    Registered User
    Join Date
    Jun 2007
    Location
    爱国者同盟Chinese Patriot League
    Posts
    2
    return arrays from COM to JScript ?


    http://groups.google.ca/group/micros...a3d43af7c78d92

    As Peter Torr has described before, a JScript array is an IDispatchEx object with a length property and numeric property names.

    JScript takes "array[0]" as "array.0", array is a IDispatchEx !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function passing argument..array ?
    By jochen in forum C Programming
    Replies: 2
    Last Post: 09-30-2007, 11:53 AM
  2. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM
  3. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 11:09 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21