Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Custom IE button calling BHO

Custom IE button calling BHO

Scheduled Pinned Locked Moved C#
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Haim Nachum
    wrote on last edited by
    #1

    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
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups