Reading JS variable from BHO in IE9

I have a BHO Internet Explorer that can execute a script on the current website and then read the variables that were assigned in this script. Unfortunately, with IE9 (I tested with RC), reading the JS variable results in HRESULT 0x80020006.

The script set assigns the JS variable as follows:

this.<js_var> = <value>

where thisis the current Window object. It is executed using

hr = pWindow->execScript( ccom_js, lang, &vEmpty );

and the js variable is read using

bool get_js_var( CComPtr<IDispatch> pDisp, LPOLESTR name, VARIANT *dest )
{
  DISPID id;
  HRESULT hr = pDisp->GetIDsOfNames( IID_NULL, &name, 1, LOCALE_SYSTEM_DEFAULT, &id );
  if ( SUCCEEDED( hr ) ) {
    VariantInit( dest );
    VariantClear( dest );
    DISPPARAMS dp = { 0, 0, 0, 0 };
    hr = pDisp->Invoke( id, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &dp, dest, NULL, NULL );
    if ( SUCCEEDED( hr ) ) {
      return true;
    } else {
      LOG( _T( "failed to get var contents, hresult = 0x%lx" ), hr );
    }
  } else {
    LOG( _T( "failed to get id of var name, hresult = 0x%lx" ), hr );
  }

  return false;
}

where pDispobtained with document->get_Script( &pDisp );.

This code works fine in previous versions of IE, in Windows XP, Vista, and 7. In IE9, a script is executed (I can raise warnings, etc.), but the variable cannot be read. What change in IE9 is causing this problem?

+3
source
1

IDispatch->GetIDsOfNames() IE9, , get_Script() IDispatch get_Script() :

HRESULT hr = pDispEx->GetDispID( CComBSTR( name ), fdexNameImplicit, &id );

RESULT hr = pDisp->GetIDsOfNames( IID_NULL, &name, 1, LOCALE_SYSTEM_DEFAULT, &id );

id, pDispEx->Invoke().

IDispatchEx, :

CComPtr<IDispatchEx> pDispEx;
hr = pDisp->QueryInterface(IID_IDispatchEx, (void**)&pDispEx);`
+3

Source: https://habr.com/ru/post/1795462/


All Articles