Re: IObjectWithSite and IOLECommandTarget Issue

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



John Littleton <John Littleton@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I am implementing the IObjectWithSite interface to handle acquiring a
reference to the browser. And I am implementing the IOLECommandTarget
interface in order to receive the click notification via the Exec
method.

If I set up the registry entries under "Browser Helper Objects" my
.dll is being properly instantiated by IE when it loads, and I am
successfully acquiring a reference to the browser with "wb =
CType(pUnkSite, SHDocVw.IWebBroswer2)" in the SetSite method of
IObjectWithSite.

However, upon clicking the custom toolbar button, the SetSite method
is apparently called again

Actually, a new instance of your object is created, and SetSite called
on it. You've registered the same object as two different browser
extensions - a BHO and a toolbar button handler. IE does not know that
both are backed by the same object, it creates a separate instance for
each role.

Is there a reason you register the same object twice?

and I encounter the following error when
attempting to acquire the broswer reference:

Unable to cast COM object of type 'System.__ComObject' to interface
type 'SHDocVw.IWebBrowser2'.

For reasons that are not quite clear to me, BHO gets IWebBrowser2
pointer in SetSite, whereas toolbar button handler gets IShellBrowser.
To get from IShellBrowser to IWebBrowser2, query the pointer for
IServiceProvider and call QueryService(SID_SWebBrowserApp)
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.


Quantcast