BHO Development using managed code

Browser Helper Object (BHO) is a plug-in for Internet Explorer (IE). BHO let developers to drive IE. A plug-in is a program which extends the functionality of a browser. It can be used to retrieve information or modify the content of the webpage that is being displayed in a browser window, or it may just be used to provide the user an option to see the day’s Stock market status or, weather in a toolbar.

To start BHO development can be depressing at the very first beginning to learn all those things. As a beginner I want to share my experience to other beginners. Here I am going to explain the simple implementation of BHO.

A Browser Helper Object is a COM object loaded for each IE window. As a browser window is opened, it creates its own copy of the BHO; and, when the window is closed, it destroys its copy of the BHO. You will need a COM dll which interact with browser. This need to done by implementing the IObjectWithSite in class. We need to use COM interop library to implement COM dll in our dotNet project.

While we are writing in C#, we also need to write the interface IObjectWithSite ourselves. Also, we have to then implement the interface in your BHO. To interact with the HTML document, we will need to add a reference to the Microsoft.mshtml library & to get the DOM or the webpage currently in the browser, we will have to add SHDocVw library as a reference. Also, we will have to add 2 functions which will register (& unregister) our COM component as a BHO with Internet Explorer with the key.

Say Hello to BHO development world:

Let’s create a Hello world project regarding BHO. Start a new C# class library project. I named it as ‘HelloBHOWorld’.

Continue reading