0
Answer

IObjectWithSite and IOLECommandTarget Issue

Ask a question

Greetings,

I am building a VB.NET dll to respond to the click event of a custom button added to IE's toolbar. In response to the button click the .dll will print the current page to a specific printer without the user needing to choose it from the print dialog.

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 the IObjectWithSite implementation.

However, upon clicking the custom toolbar button, the SetSite method is apparently called again, 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'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Any ideas on why this is happening?

Thanks