Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7544429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:40:11+00:00 2026-05-30T08:40:11+00:00

I have an ActiveX component which receives byte array from javascript and process it.

  • 0

I have an ActiveX component which receives byte array from javascript and process it. I wrote the following code and it worked for IE7 & 8 but in IE 9 it is failing while i call IDispatch::Invoke please help me to resolve it

if(pszBufData->vt == VT_DISPATCH)
        {       
            BYTE * pData = new BYTE[dwSize];

            IDispatch *pDisp = pszBufData->pdispVal;
            pDisp->AddRef();

            DISPPARAMS dispparamsNoArgs = { NULL, NULL, 0, 0 };

            VARIANT var;
            VariantInit(&var);

            HRESULT hr = pDisp->Invoke(DISPID_NEWENUM, IID_NULL, GetUserDefaultLCID(), DISPATCH_PROPERTYGET, &dispparamsNoArgs, &var, NULL, NULL);


            int i=0;
            if (SUCCEEDED(hr)) 
            {

             if (var.vt == VT_UNKNOWN) 
             {
                 IEnumVARIANT *pEnum = NULL;
                 if SUCCEEDED(var.punkVal->QueryInterface(IID_IEnumVARIANT, (void**) &pEnum)) 
                 {
                     VARIANT item;
                     VariantInit(&item);

                     pEnum->Reset();
                     while ( (pEnum->Next(1, &item, NULL) && S_FALSE) != S_FALSE) 
                     {                   
                         if (item.vt == VT_I4) 
                         {  
                             //AfxMessageBox(_T("SendData"));
                             pData[i] = item.cVal;
                             i++;
                         }
                         VariantClear(&item);
                     }
                     pEnum->Release();
                 }
                   var.punkVal->Release();
             }
            }

            /*VariantClear(&var);*/
            pDisp->Release();


        }

The java script code

<HTML>
<HEAD>
    <SCRIPT LANGUAGE="JavaScript" FOR="window" EVENT="onLoad()">
<!--

var arr = new Array(0x1, 0xA,0x20)

//CSDS_Communication1.ConfigCon("COM1",9600)

CSDS_Communication1.SendData("COM1",arr,3)


-->
    </SCRIPT>
<TITLE>New Page</TITLE>
</HEAD>
<BODY>
    <OBJECT ID="CSDS_Communication1" WIDTH=100 HEIGHT=51
     CLASSID="CLSID:73D79990-090E-48CB-8857-E6BF50F42E63">
        <PARAM NAME="_Version" VALUE="65536">
        <PARAM NAME="_ExtentX" VALUE="2646">
        <PARAM NAME="_ExtentY" VALUE="1323">
        <PARAM NAME="_StockProps" VALUE="0">
    </OBJECT>
</BODY>
</HTML>

The issue is fixed with the below code
Fixed Code

    BYTE * pData = new BYTE[dwSize];

    /* retrieving IDispatch */
    IDispatch *disp = pszBufData->pdispVal;
    if (pszBufData->vt & VT_BYREF)
        disp = *(pszBufData->ppdispVal);

    /* getting array's length */
    DISPPARAMS params;
    FillMemory(&params, sizeof(DISPPARAMS), 0);
    VARIANT res;

    DISPID dl = 0;
    LPOLESTR ln = L"length";
    HRESULT hr = disp->GetIDsOfNames(IID_NULL, &ln, 1, LOCALE_USER_DEFAULT, &dl);
    if (FAILED(hr))
        return false;

    // get the number of elements using the DISPID of length parameter

    hr =disp->Invoke(dl, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,&params, &res, NULL, NULL);
    if (FAILED(hr))
        return false;


    VARIANT len1;
    VariantInit(&len1);

    VariantChangeType(&len1, &res, 0, VT_I4);

    LONG len = len1.lVal;

    /* summing elements */

    for (int i = 0; i < len; i++)
    {
        std::wstring strIndex;// = StringUtils::IntToString(i);

        wchar_t buf[8];
        _itow(i,buf,10);
        strIndex.append(buf);

        DISPID dispid;

        LPOLESTR pIndex = reinterpret_cast<LPOLESTR>(const_cast<WCHAR *>(strIndex.data()));


        hr = disp->GetIDsOfNames( IID_NULL, &pIndex, 1, LOCALE_USER_DEFAULT, &dispid );
         if (FAILED(hr))
             continue;


        /*std::stringstream ss;
        ss << ind =" CComBSTR(ss.str().c_str());">GetIDsOfNames(IID_NULL, &ind, 1, LOCALE_USER_DEFAULT, &dispid));*/
        hr = disp->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &params, &res, NULL, NULL);
        if (FAILED(hr))
             continue;

        VARIANT val1;
        VariantInit(&val1);

        VariantChangeType(&val1, &res, 0, VT_I4);

        pData[i] = val1.lVal;


    }

Aprroach 2:

IDispatch *disp = pszBufData->pdispVal;
    if (pszBufData->vt & VT_BYREF)
        disp = *(pszBufData->ppdispVal);

    // Get IDispatchEx on input IDispatch
    CComQIPtr<IDispatchEx> pdispexArray(disp);
    if ( ! pdispexArray )
        return E_NOINTERFACE;

    // Get array length DISPID
    DISPID dispidLength;
    CComBSTR bstrLength(L"length");
    HRESULT hr = pdispexArray->GetDispID(bstrLength, fdexNameCaseSensitive, &dispidLength);
    if (FAILED(hr))
        return false;

     // Get length value using InvokeEx()
    CComVariant varLength;
    DISPPARAMS dispParamsNoArgs = {0};
    hr = pdispexArray->InvokeEx(dispidLength, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dispParamsNoArgs, &varLength, 
        NULL, NULL);
    if (FAILED(hr))
        return hr;

    ATLASSERT(varLength.vt == VT_I4);
    const int count = varLength.intVal;

    BYTE * pData = new BYTE[count];

    // For each element in source array:
    for (int i = 0; i < count; i++)
    {
        CString strIndex;
        strIndex.Format(L"%d", i);

        // Convert to BSTR, as GetDispID() wants BSTR's
        CComBSTR bstrIndex(strIndex);
        DISPID dispidIndex;
        hr = pdispexArray->GetDispID(bstrIndex, fdexNameCaseSensitive, &dispidIndex);
        if (FAILED(hr))
            break;

        // Get array item value using InvokeEx()
        CComVariant varItem;
        hr = pdispexArray->InvokeEx(dispidIndex, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dispParamsNoArgs, &varItem, 
            NULL, NULL);
        if (FAILED(hr))
            break;

        ATLASSERT(varItem.vt == VT_I4);

        pData[i] = varItem.intVal;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:40:12+00:00Added an answer on May 30, 2026 at 8:40 am

    I think you have the wrong diagnostic about your problem. The title should be: jscript9 doesn’t support NewEnum for array objects. If anything, I’m surprised it was working for you on previous version – I didn’t try it, but on IE9 (jscript9.dll) JavaScript arrays cannot be accessed with neither SAFEARRAY nor with IEnumVeriant and any other Array construct. Javascript array are nothing but regular IDispatchEx objects. You can access the individual items as “0”, “1” and “2”.

    The following post from Eric Lippert explains JavaScript arrays: http://blogs.msdn.com/b/ericlippert/archive/2003/09/22/53061.aspx

    In your C++ code, with your pDisp pointer to IDispatch do the following (pseudo code for first element):

    DISPID dispid;
    wchar_t name[] = L"0";
    pDisp->GetIDsOfNames( IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid );
    pDisp->Invoke( dispid, ... );
    

    This is very JavaScript’y thing. VBScript will pass a completely different construct (probably SAFEARRAY). You can investigate exactly what you are getting at pDisp, if you pDisp->GetTypeInfo, and use the ITypeInfo::GetTypeAttr to get information about the type. TYPEATTR.cVars returns the number of properties, and GetVarDesc returns information about each variable. Verify there are no ‘Length’ or ‘Count’ or _NewEnum variables, while there are “0”, “1”, “2” variables which you can extract.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI I have created a CAB file for an ActiveX component which is wrapper
i have made a very simple labview VI which has an activeX component in
I have a C# .NET component that is being called from a COM out-of-process
basically I want to encapsulate a simple component from code that I already have.
I have installed my windows application that uses TeeChart ActiveX (a COM Component for
I have an ActiveX control (an OCX file) which raises an event. I want
I have an ActiveX object which extends some functions. I have a web page
I have an ActiveX control that I'm loading with JavaScript in Internet Explorer. It
I have existing managed and unmanaged software using an ActiveX component supplied by a
I have several ActiveX components that needed to be accessed from a C# project.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.