Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Browser Helper Objects and Scripts

1,792 views
Skip to first unread message

Jean Lacoste

unread,
Aug 17, 2001, 9:54:37 AM8/17/01
to
Hello,

I would like a script (javascript ou vbscript) to communicate, send an event
or something else, to a running Browser Helper Objects. The script sould
signal its presence to the BHO

Any idea ?

Thanks.

Jean Lacoste

Igor Tandetnik

unread,
Aug 17, 2001, 10:16:50 AM8/17/01
to
BHO can sink NavigateComplete2 event and install an IDispatch pointer to
some object it implements as a property of window object. Sample below is
pseudocode just outlining the sequence of operations

IDispatch *pMyObject; // object your BHO implelemts
IDispatch *pWindow; // initialized e.g. with
IHTMLDocument2::get_parentWindow
IDispatchEx *pWndEx;
pWindow->QueryInterface(&pWndEx);
DISPID dispid;
// Adding new property to window object
pWndEx->GetDispID("MyBHOObject", fdexNameEnsure, &dispid);
pWndEx->Invoke(dispid, ..., DISPATCH_PROPERTYPUTREF, pMyObject, ...);

After that, script can do

window.MyBHOObject.DoSomething();

or simply

MyBHOObject.DoSomething();

since window is implied as a global object.
--
With best wishes,
Igor Tandetnik

"Jean Lacoste" <x...@yyy.zzz> wrote in message
news:xm9f7.175$yG6.2...@nnrp6.proxad.net...

Jean Lacoste

unread,
Aug 17, 2001, 11:49:30 AM8/17/01
to
Hello,
"Igor Tandetnik" <itand...@whenu.com> a écrit dans le message news:
OUSLCdyJBHA.1952@tkmsftngp02...

> BHO can sink NavigateComplete2 event and install an IDispatch pointer to
> some object it implements as a property of window object. Sample below is
> pseudocode just outlining the sequence of operations
>
> IDispatch *pMyObject; // object your BHO implelemts
> IDispatch *pWindow; // initialized e.g. with
> IHTMLDocument2::get_parentWindow
> IDispatchEx *pWndEx;
> pWindow->QueryInterface(&pWndEx);
> DISPID dispid;
> // Adding new property to window object
> pWndEx->GetDispID("MyBHOObject", fdexNameEnsure, &dispid);
> pWndEx->Invoke(dispid, ..., DISPATCH_PROPERTYPUTREF, pMyObject, ...);
>
> After that, script can do
>
> window.MyBHOObject.DoSomething();
>
> or simply
>
> MyBHOObject.DoSomething();
>
> since window is implied as a global object.
> --
> With best wishes,
> Igor Tandetnik

Thank you very, very, very, very much ! I'll try it.

Jean Lacoste

Jean Lacoste

unread,
Aug 18, 2001, 5:58:12 AM8/18/01
to
Hello,

> BHO can sink NavigateComplete2 event and install an IDispatch pointer to
> some object it implements as a property of window object. Sample below is
> pseudocode just outlining the sequence of operations
>
> IDispatch *pMyObject; // object your BHO implelemts
> IDispatch *pWindow; // initialized e.g. with
> IHTMLDocument2::get_parentWindow
> IDispatchEx *pWndEx;
> pWindow->QueryInterface(&pWndEx);
> DISPID dispid;
> // Adding new property to window object
> pWndEx->GetDispID("MyBHOObject", fdexNameEnsure, &dispid);
> pWndEx->Invoke(dispid, ..., DISPATCH_PROPERTYPUTREF, pMyObject, ...);

Well, it nearly works !

Here is my code (pascal object) :

var
idx: IDispatchEx;
putid: TDispID;
tp: TDispParams;
vtval: Variant;
begin
if FHTMLWindow2.QueryInterface(IDispatchEx, idx)=0 then
begin
idx.getdispid('jtest', fdexNameEnsure, idMenuPopupCommand);

// the IDispatch interface of my BHO
vtval := self as IDispatch;

putid := DISPID_PROPERTYPUT;

tp.rgvarg := @vtval;
tp.cArgs := 1;
tp.rgdispidNamedArgs := @putid;
tp.cNamedArgs := 1;

res := idx.invokeex(idMenuPopupCommand, locale_user_default,
DISPATCH_PROPERTYPUT, @tp,
Nil, Nil, Nil);

if Failed(res) then
MessageBox(0, 'test', Nil, MB_OK);
end;
end;

If I invokeex with DISPATCH_PROPERTYPUTREF, the function fails with
DISP_E_MEMBERNOTFOUND. It looks like the property is read/only because the
arg is not BYREF. But I don't know how to pass the IDispatch as BYREF on the
variant. I tried to initialize a tagVariant struct but the problem persists.

So, if invoeex with DISPATCH_PROPERTYPUT (not PUTREF), it works and when the
new function is called from the script, the Invoke function of my IDispatch
is called but the DispId is not the one created with idx.getdispid. The
value is 0.

Have you an idea ?

Jean.

Matthew Ellis

unread,
Aug 19, 2001, 2:30:56 PM8/19/01
to
"Igor Tandetnik" <itand...@whenu.com> wrote in message
news:OUSLCdyJBHA.1952@tkmsftngp02...

> // Adding new property to window object
> pWndEx->GetDispID("MyBHOObject", fdexNameEnsure, &dispid);

It might be an idea to use a name that is less generic - a GUID perhaps. You
can always assign this to an easier to use variable in the script.

Matt
m.t....@bigfoot.com

Igor Tandetnik

unread,
Aug 20, 2001, 10:36:37 AM8/20/01
to
The DISPID you get with GetDispId has meaning fow window object
dispinterface, and is the DISPID of the new property. It doesn't relate in
any way to DISPIDs you yourself implement. Suppose you have this line of
script:

window.jtest.DoSomething();

The script first uses GetIDsOfNames on window object to find DISPID of
"jtest", then invokes with propertyget and gets your IDispatch. It then
calls GetIDsOfNames on your object to find DISPID of "DoSometing", and
finally invokes it.

Now suppose we have that line of script:

window.jtest();

The script gets DIPSID for jtest as before. Then it tries to inoke it as
method (since there are parentheses after the name) and fails. It then
assumes that "jtest" is an IDispatch property on which a default method (a
method with DISPID of DISPID_VALUE, or zero) should be called. So it invokes
window.jtest with propertyget, gets your IDispatch, and invokes DISPID_VALUE
with propertyget | method.


--
With best wishes,
Igor Tandetnik

"Jean Lacoste" <x...@yyy.zzz> wrote in message

news:a7ell9...@chnou.factorial.l...

Jean Lacoste

unread,
Aug 21, 2001, 11:18:50 AM8/21/01
to
Salut,

Igor Tandetnik <itand...@whenu.com> a écrit :


> The DISPID you get with GetDispId has meaning fow window object
> dispinterface, and is the DISPID of the new property. It doesn't relate in
> any way to DISPIDs you yourself implement. Suppose you have this line of
> script:
>
> window.jtest.DoSomething();
>
> The script first uses GetIDsOfNames on window object to find DISPID of
> "jtest", then invokes with propertyget and gets your IDispatch. It then
> calls GetIDsOfNames on your object to find DISPID of "DoSometing", and
> finally invokes it.
>
> Now suppose we have that line of script:
>
> window.jtest();
>
> The script gets DIPSID for jtest as before. Then it tries to inoke it as
> method (since there are parentheses after the name) and fails. It then
> assumes that "jtest" is an IDispatch property on which a default method (a
> method with DISPID of DISPID_VALUE, or zero) should be called. So it invokes
> window.jtest with propertyget, gets your IDispatch, and invokes DISPID_VALUE
> with propertyget | method.

Thank you, I'm progressing at light speed ! (I don't know if I can say
that in english)...

I have another small problem : calling the Invoke method of the
IDispatchEx interface, I cannot pass DISPATCH_PROPERTYPUTREF as you say
(and msdn too). I just can use DISPATCH_PROPERTYPUT. I don't understand
why. With the REF version, Invoke returns the DISP_E_MEMBERNOTFOUND
error.
But it looks like working with DISPATCH_PROPERTYPUT. Have you an idea ?

Thank you again.

Jean

Igor Tandetnik

unread,
Aug 21, 2001, 11:33:47 AM8/21/01
to
If it ain't broken, don't fix it.

--
With best wishes,
Igor Tandetnik

"Jean Lacoste" <je...@chnou.factorial.l> wrote in message
news:slrn9o4tr...@chnou.factorial.l...

0 new messages