0

Hi We are using IE9 in non-compatibility mode.

We are doing something like this to read JS variable values from browser side:

ComPtr<IDispatch> disp;
m_spBrowser->get_Document(&disp);

CComQIPtr<IHTMLDocument2> htmlDoc = disp;
if( !htmlDoc ) return ZString();

CComPtr<IHTMLWindow2> spWindow;
htmlDoc->get_parentWindow(&spWindow);

CComVariant varRes;
CComDispatchDriver dispWindow = spWindow;
if( dispWindow ) {
    HRESULT hr = dispWindow.GetPropertyByName(L"returnValue", &varRes);
    if( SUCCEEDED(hr) && SUCCEEDED(varRes.ChangeType(VT_BSTR)) ) 
        return CString(varRes.bstrVal);
}
return CString();

We are using old version of ATL.

Now this routine always fails when run in IE9 non-compatibility mode. "returnValue" is Null and we get 0 value for GetLastError.

Any ideas? Is it a known issue and if so any fixes/workarounds?

Pranab
  • 41
  • 5
  • We expect to get window.top.returnValue and access JS variables from C++ side. We are using MSVC 6 ATL if it helps. – Pranab Aug 05 '13 at 07:56
  • Check [this](http://stackoverflow.com/questions/18342200/how-do-i-call-eval-in-ie-from-c/18349546#18349546) for an example of `IDispatchEx::GetDispID` on `window` object. – noseratio Aug 30 '13 at 02:11

1 Answers1

0

What you are doing here is querying property named returnValue from the COM object, for which you have IHTMLWindow2 interface pointer. This does not have to work out because you assume the property exists, and documentation says otherwise:

returnValue property:

Remarks

This property applies only to windows created by using the IHTMLWindow2::showModalDialog method.

More to that, the property belongs to IHTMLDialog interface, so you could perhaps access it directly without relying on CComDispatchDriver's abilities to find path to it via IDispatch/IDispatchExnamed property access.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • We set the JS object value as window.top.returnValue=. According to your logic, the code would have failed for all browsers..not only IE9. Also why would I get the error value as 0(action completed successfully)? – Pranab Aug 05 '13 at 09:20
  • `1` my logic is that you might be getting the property more accurately instead of expecting to be found via name lookup `2` `GetLastError` is not expected to get you any error code here, instead you need to step into the function and check things there. `hr` might have a related error code. – Roman R. Aug 05 '13 at 09:35
  • Any idea how I can get the IHTMLDialog object in the above code/function? I am creating the modal dialog from else where and I just need to read the returnValue property from the above funtion. Also can it be a limitation of ATL 3.0 becasue all other browser/platforms work fine.. – Pranab Aug 05 '13 at 10:35
  • So I tried this but does not work(gives error at QueryInterface) ComPtr spWindow; htmlDoc->get_parentWindow(&spWindow); hr = spWindow->get_external(&disp); CComQIPtr spDlg; hr = disp->QueryInterface(IID_IHTMLDialog , (void **) &spDlg); – Pranab Aug 05 '13 at 12:03