How to call JavaSCRIPT Function in axWebBrowser?

How to call JavaSCRIPT Function in axWebBrowser?

Post by chiu » Wed, 17 Apr 2002 19:17:24



How to call JavaSCRIPT Function in axWebBrowser?
 
 
 

How to call JavaSCRIPT Function in axWebBrowser?

Post by MS » Sun, 28 Apr 2002 09:01:22



Quote:> How to call JavaSCRIPT Function in axWebBrowser?

Hi,

The script hosting group is a much better place for this question (added).

Peter

--

This must be the disclaimer I waited years to read:
http://www.microsoft.com/info/cpyright.htm

 
 
 

How to call JavaSCRIPT Function in axWebBrowser?

Post by Jim Christophe » Tue, 30 Apr 2002 22:33:51


You have two options.  Both begin with the same code to fetch the script
name space and locate the routine in question:

// all this code is untested ...

// get the HTML Document
CComPtr< IDispatch > spDispatch;
spWebBrowser->get_Document( &spDispatch );

// get the script
CComQIPtr< IHTMLDocument > spDoc = spDisptach;
spDisptach = NULL;

spDoc->get_Script( &spDispatch );

// find the function you want
// in this example, we look for a function named
//    "MyFunction"
DISPID dispid;
LPOLESTR lpzName = L"MyFunction";
spDisptach->GetIDsOfNames( IID_NULL, &lpzName, 1, LCID_SYSTEM_DEFAULT,
&dispid );

At this point, you can either call the routine directly, or fetch a
reference to the routine and call the function via the reference.  The
former is simpler:

// call the function directly
CComVariant vResult;
DISPPARAMS params;
EXCEPINFO excep;
UINT err = 0;

ZeroMemory( &params, sizeof( DISPPARAMS ) );
ZeroMemory( &excep, sizeof( EXCEPINFO ) );

spDispatch->Invoke( dispid, IID_NULL, LCID_SYSTEM_DEFAULT, DISPATCH_METHOD,
&params, &vResult, &excep, &err );

To get a reference to the function:

// get the function as a PROPERTY of the script
CComVariant vResult;
DISPPARAMS params;
EXCEPINFO excep;
UINT err = 0;

ZeroMemory( &params, sizeof( DISPPARAMS ) );
ZeroMemory( &excep, sizeof( EXCEPINFO ) );

spDispatch->Invoke( dispid, IID_NULL, LCID_SYSTEM_DEFAULT,
DISPATCH_PROPERTYGET, &params, &vResult, &excep, &err );

// now vResult contains the IDispatch representing the function object.
// to call the function via this reference, Invoke the default dispinterface
member, identified by
// the DISPID DISPID_VALUE:
ZeroMemory( &params, sizeof( DISPPARAMS ) );
ZeroMemory( &excep, sizeof( EXCEPINFO ) );
err = 0;
CComVariant vFuncResult;
vResult.pdispVal->Invoke( DISPID_VALUE, IID_NULL, LCID_SYSTEM_DEFAULT,
DISPATCH_METHOD, &params, &vFuncResult, &excep, &err );

HTH;
jim christopher





> > How to call JavaSCRIPT Function in axWebBrowser?

> Hi,

> The script hosting group is a much better place for this question (added).

> Peter

> --

> This must be the disclaimer I waited years to read:
> http://www.microsoft.com/info/cpyright.htm