Anthony Roach

I have a C++ application that embeds a CHtmlView and calls JavaScript functions via the IDispatchEx interface retrieved from the IHTMLDocument2::get_Script(). Normally it works fine and my application is able to get the DISPID for the JavaScript function using IDispatchEx::GetDispID(), but sometimes on the first page load IDispatchEx::GetDispID() returns DISP_U_UNKNOWNNAME for all the JavaScript functions defined in the page.

I am able to work around this problem by loading a dummy first page, but I'd like to find a real permanent solution.

I added code to enumerate all the members using IDispatchEx::GetNextDispID(), but it doesn't ever enumerate any of JavaScript functions. It does enumerate non-JavaScript members such as "onbeforeunload", "onafterprint", "top", "self", etc...

This really has me stumped. The fact that it doesn't happen every time, and certain computers seem to reproduce the problem and others don't makes me think it is perhaps a race condition.



Re: Internet Explorer Extension Development IE6: Problem Calling JavaScript Functions Through IDispatch.

Appxweb

Hi Anthony,

I am not sure why you are experiencing your problems, but one "guess" as to the cause may have to do with the use of IDispatchEx.  IDispatchEx is an expando object which allows you to add and remove members to  an object. Scripting languages like javascript use it to dynamically add and remove members to the IE Script Host (When you call get_Script and query IDispatchEx  you get IE's script host.)  This may cause  sequencing problems with your app and certain web pages scripts depending on when they are executed.  As I said this is a guess, but looking at other examples that call JScript functions from C++ they tend to use IDispatch not IDispatchEx.  Have a look at the following article for an example:

JavaScript call from C++
A class for easy implementation of JavaScript calls from C++ code
http://www.codeproject.com/com/jscalls.asp
 
Regards
 
Ian





Re: Internet Explorer Extension Development IE6: Problem Calling JavaScript Functions Through IDispatch.

Anthony Roach

Thanks for the reply. I suspected something like you suggested, so I added code to "fallback" on IDispatch::GetIDsOfNames() if IDispatchEx::GetDispID() failed, but it did not help. Unfortunately, even if IDispatch::GetIDsOfNames() worked, we rely heavily on the ability to do case insensitive DispID lookup that only IDispatchEx::GetDispID() provides.