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. Problem Getting C# BHO To Work

Problem Getting C# BHO To Work

Scheduled Pinned Locked Moved C#
csharpvisual-studiodebugginghelp
4 Posts 2 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.
  • K Offline
    K Offline
    Khoramdin
    wrote on last edited by
    #1

    Hello everyone, I have what should be a relatively simple C# .NET 2.0 IE BHO that I am really struggling with. The goal of the BHO is to provide a hook when the users opens a web-page the HelloWorld! message appears. I am using Visual Studio 2005 Profesional Edition and do the following: 1- Build Solution (F6) 2- Fire an Internet Explorer (IE) 3- (From Visual Studio) Debug -> Attach to Process... 4- Select the Internet Explorer (IE) that was started in 1. 5- Attach At this point I can see in the StatusBar loading message for verious files. If I am not mistaken at this point my simple BHO should be attached to the Internet Explorer (IE). when I move from the webpage to other pages I expect for the HelloWorld MessageBox to pop-up once the website is loaded. But sadly, nothing happens! The codes are: IObjectWithSite.cs

    using System;
    using System.Runtime.InteropServices;

    namespace WebWatcher
    {
    [ComVisible(true),
    InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
    Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")]
    public interface IObjectWithSite
    {
    [PreserveSig]
    int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
    [PreserveSig]
    int GetSite(ref Guid guid, out IntPtr ppvSite);
    }
    }

    BHO.cs

    using System;
    using System.Collections.Generic;
    using System.Text;
    using SHDocVw;
    using mshtml;
    using System.IO;
    using Microsoft.Win32;
    using System.Runtime.InteropServices;

    namespace WebWatcher
    {
    [
    ComVisible(true),
    Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),
    ClassInterface(ClassInterfaceType.None)
    ]
    public class BHO : IObjectWithSite
    {
    private SHDocVw.WebBrowser webBrowser;

        public void OnDocumentComplete(object pDisp, ref object URL)
        {
            System.Windows.Forms.MessageBox.Show("HelloWorld!");
        }
    
        #region WebWatcher Internal Functions
        public int SetSite(object site)
        {
    
            if (site != null)
            {
                webBrowser = (SHDocVw.WebBrowser)site;
                webBrowser.DocumentComplete += new DWebBrowserEvents2\_DocumentCompleteEventHandler(this.OnDocumentComplete);
            }
            else
            {
                webBrowser.DocumentComplete -= new DWebBrowserEvents2\_DocumentCompleteEventHandler(this.OnDocumentComplete);
                webBrowser = null;
            }
    
            return 0;
    
        }
    
    N 1 Reply Last reply
    0
    • K Khoramdin

      Hello everyone, I have what should be a relatively simple C# .NET 2.0 IE BHO that I am really struggling with. The goal of the BHO is to provide a hook when the users opens a web-page the HelloWorld! message appears. I am using Visual Studio 2005 Profesional Edition and do the following: 1- Build Solution (F6) 2- Fire an Internet Explorer (IE) 3- (From Visual Studio) Debug -> Attach to Process... 4- Select the Internet Explorer (IE) that was started in 1. 5- Attach At this point I can see in the StatusBar loading message for verious files. If I am not mistaken at this point my simple BHO should be attached to the Internet Explorer (IE). when I move from the webpage to other pages I expect for the HelloWorld MessageBox to pop-up once the website is loaded. But sadly, nothing happens! The codes are: IObjectWithSite.cs

      using System;
      using System.Runtime.InteropServices;

      namespace WebWatcher
      {
      [ComVisible(true),
      InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
      Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")]
      public interface IObjectWithSite
      {
      [PreserveSig]
      int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
      [PreserveSig]
      int GetSite(ref Guid guid, out IntPtr ppvSite);
      }
      }

      BHO.cs

      using System;
      using System.Collections.Generic;
      using System.Text;
      using SHDocVw;
      using mshtml;
      using System.IO;
      using Microsoft.Win32;
      using System.Runtime.InteropServices;

      namespace WebWatcher
      {
      [
      ComVisible(true),
      Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),
      ClassInterface(ClassInterfaceType.None)
      ]
      public class BHO : IObjectWithSite
      {
      private SHDocVw.WebBrowser webBrowser;

          public void OnDocumentComplete(object pDisp, ref object URL)
          {
              System.Windows.Forms.MessageBox.Show("HelloWorld!");
          }
      
          #region WebWatcher Internal Functions
          public int SetSite(object site)
          {
      
              if (site != null)
              {
                  webBrowser = (SHDocVw.WebBrowser)site;
                  webBrowser.DocumentComplete += new DWebBrowserEvents2\_DocumentCompleteEventHandler(this.OnDocumentComplete);
              }
              else
              {
                  webBrowser.DocumentComplete -= new DWebBrowserEvents2\_DocumentCompleteEventHandler(this.OnDocumentComplete);
                  webBrowser = null;
              }
      
              return 0;
      
          }
      
      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      From the number of posts on this subject you seem to be over your head. Possibly its time to give it up and try another project.


      only two letters away from being an asset

      K 1 Reply Last reply
      0
      • N Not Active

        From the number of posts on this subject you seem to be over your head. Possibly its time to give it up and try another project.


        only two letters away from being an asset

        K Offline
        K Offline
        Khoramdin
        wrote on last edited by
        #3

        Hello Mark, Thanx for your reply. Now, I know that my messages can be read by other! *wink* By the way, if it bothers you so much that I post here, I surly can stop and take my postings and problems to another forum since I don't mean to upset anyone. Since you have been readin my posting, then you should know by know, that they are on the same subject but as I am spending more time reading about the issue, they are changing since I feel as I am getting closer to the source of the problem. :) I was wondering if you got the MVP title by very same approach of moving to the next topic once you are stuck on one?!!! *wink* Since we are on the same topic, let me ask you this. When a Class Library is Attached to a running process, then I guess I should NOT be able to delete the dll file since that file should be loaded and used with the running poccess? In my case I can delete the WebWatcher.dll file and that makes me think if the file is actually been attached! What are your thoughts on this? Any information would be appriciated, mate. Happy thanx-giving, mate. khoramdin -- modified at 18:39 Saturday 17th November, 2007

        N 1 Reply Last reply
        0
        • K Khoramdin

          Hello Mark, Thanx for your reply. Now, I know that my messages can be read by other! *wink* By the way, if it bothers you so much that I post here, I surly can stop and take my postings and problems to another forum since I don't mean to upset anyone. Since you have been readin my posting, then you should know by know, that they are on the same subject but as I am spending more time reading about the issue, they are changing since I feel as I am getting closer to the source of the problem. :) I was wondering if you got the MVP title by very same approach of moving to the next topic once you are stuck on one?!!! *wink* Since we are on the same topic, let me ask you this. When a Class Library is Attached to a running process, then I guess I should NOT be able to delete the dll file since that file should be loaded and used with the running poccess? In my case I can delete the WebWatcher.dll file and that makes me think if the file is actually been attached! What are your thoughts on this? Any information would be appriciated, mate. Happy thanx-giving, mate. khoramdin -- modified at 18:39 Saturday 17th November, 2007

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          Khoramdin wrote:

          I was wondering if you got the MVP title by very same approach of moving to the next topic once you are stuck on one?!!!

          I'm not stuck, you are. ;P

          Khoramdin wrote:

          I surly can stop and take my postings and problems to another forum

          Bye.


          only two letters away from being an asset

          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