Custom IE button calling BHO
-
Im trying to build a simple bho object that handles a custom IE button click event. Ive created the needed interfaces(IOleCommandTarget,IServiceProvider,IOBJECTWITHSITE ) i have the following SetSite function implementation:
public int SetSite(object site)
{
SHDocVw.IWebBrowser2 m_pIWebBrowser2 = site as SHDocVw.IWebBrowser2;
IServiceProvider ISP = site as IServiceProvider;if (m\_pIWebBrowser2 != null) { Marshal.ReleaseComObject(m\_pIWebBrowser2); m\_pIWebBrowser2 = null; } if (Explorer != null) { Marshal.ReleaseComObject(Explorer); Explorer = null; } if (ISP != null) { Guid IID\_IUnknown = new Guid("{00000000-0000-0000-C000-000000000046}"); Guid IID\_IWebBrowserApp = new Guid("{0002DF05-0000-0000-C000-00000000046}"); object pOut; try { ISP.QueryService(ref IID\_IWebBrowserApp, ref IID\_IUnknown, out pOut); Explorer = (WebBrowserClass)Marshal.CreateWrapperOfType(pOut as IWebBrowser2, typeof(WebBrowserClass)); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message, "Talkative Browser"); } }
when im debugging i can see that the function is called twice, once when the browser is opend and two when i click my button. i provided an IServiceProvider interface to look for the browser handle when i click my button(it seems it is sending ISHELLBROWSER pointer to my SetSite). Everything is working fine except the Exec function implemented by the IOLECOMMANDTARGET interface is not being called. here is my IOLECOMMANDTARGET code:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct OLECMDTEXT
{
public uint cmdtextf;
public uint cwActual;
public uint cwBuf;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public char rgwz;
}\[StructLayout(LayoutKind.Sequential)\] public struct OLECMD { public uint cmdID; public uint cmdf; } \[ComImport, Guid("b722bccb-4e68-101b-a2bc-00aa00404770"), InterfaceType(ComInterfaceType.Interfa