Re: Changing JScript global variable values dynamically

From: Peter (peter1234se_at_yahoo.se)
Date: 05/18/04


Date: 18 May 2004 06:57:43 -0700


"Igor Tandetnik" <itandetnik@mvps.org> wrote in message news:<OnWgxBcOEHA.268@TK2MSFTNGP11.phx.gbl>...
> "Peter" <peter1234se@yahoo.se> wrote in message
> news:68de87e0.0405140043.732fff47@posting.google.com
> > Using the IWebBrowser2 ActiveX plugin, I can access the html page's
> > IHTMLDocument interface and from there get access to
> > IHTMLScriptElement.
> > But is there a way to actually go into running scripts and dynamically
> > changing e.g global JScript variable values?
>
> Call IHTMLDocument::get_Script - you get an IDispatch pointer of the
> script global object. All global variables are properties on this
> object, global functions are its methods. Just manipulate them via late
> binding.

Thanks, but I cannot get it to work. GetIDsOfNames seems to fail for
evry global variable and method I try. I did check that the URL for
the page is the correct one. Where am I going wrong

        //mWeb is my IWebBrowser2 interface ptr
        IDispatch *disp = NULL;
        hr = mWeb->get_Document(&disp);
        if(SUCCEEDED(hr) && disp)
        {
                IHTMLDocument *doc = NULL;
                hr = disp->QueryInterface(IID_IHTMLDocument,(PVOID *)&doc);
                if(SUCCEEDED(hr) && doc)
                {
                        IDispatch *scDisp = NULL;
                        hr = doc->get_Script(&scDisp);
                        if(SUCCEEDED(hr) && scDisp)
                        {
                                
                                TCHAR *method = TEXT("checkForNewMail");
                                hr = scDisp->GetIDsOfNames(IID_NULL, &method,1,
                                                LOCALE_USER_DEFAULT,&dispid);
                                //hr gives ERROR here and dispid is
set to
                                //0xffffffff
                               
                                //code removed
                        }
                }
          }

Peter