Categories
Geeky/Programming

VS2005 – Browser Helper Object (BHO) Tutorial

I have been dabbling with BHO’s for some time, way back with VB6, then tried in .NET, and with C++ as well. There are so many cool things you can do with them. Anyways, most of the documentation out there is sparse and old. I told myself the next time I have to make one, I am going to document it. Well, here it is in all its glory. Sorry if the code formatting is wacked, but you get the picture. I don’t claim to be an expert, but this should work đŸ™‚
just in case, I uploaded it in txt format for better reading here

How to Create a Browser Helper Object in Visual Studio 2005 with C++
———————————————————————
1) Open Visual Studio 2005
2) File->New->Project
3) Visual C++
4) ATL
5) ATL Project
6) Name is whatever you want for this example I use “Company.Browser.Helper” without the quotes

7) The ATL Project Wizard Screen will appear, Hit Finish
8) Visual Studio will load up your project.
9) Right Click on The Company.Browser.Helper project, Add->Class
10) select ATL Simple Object, and click the Add button
11) fill in the ShortName – “BrowserHelper” without the quotes, the rest of the fields should fill in, hit next
12) IMPORTANT: Under Support: Check all boxes (ISupportErrorInfo, Connection points, IObjectWithSite (IE object Support)
13) Click Finish

Now on to the better stuff,

————————————————————–

In visual studio, Solution Explorer, Resource Files, you will see BrowserHelper.rgs, open it and add this to the bottom
(replace the GUID with the GUID that you see at the top of the file like CLSID = s ‘{GUID}’) in the other script code
This will register the BHO with IE when the DLL gets registered


HKLM
{
SOFTWARE
{
Microsoft
{
Windows
{
CurrentVersion
{
Explorer
{
'Browser Helper Objects'
{
{GUID}
}
}
}
}
}
}
}

above where it says ‘Browser Helper’ – you can change those names to be more descriptive, that will show in IE add on manager

————————————————————–

————————————————————–

By Steve Novoselac

Director of Digital Technology @TrekBikes, Father, Musician, Cyclist, Homebrewer

15 replies on “VS2005 – Browser Helper Object (BHO) Tutorial”

Hey.. we have a BHO that will open up a client file, and direct them to the appropriate web page. My question is, if the BHO isn’t installed yet, can you make it take you to the download software page?

Like

Hi,
Mayby you know how to get the pointer to new IE window when it’s created (in case of DISPID_NEWWINDOW2)? I think it’s something like WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal, but it does not work.

Like

Great sample. Exactly what I need to get started. I can’t get the project built though due to an error about the non-existance of the ATL namespace.
There are a number of lines with just “#include” and no filename specified. Is there something missing?

Like

Hi Steve – everyone should definitely follow the text version. Once I did that, it all works fine. Thanks for the lesson.

Like

Ellie, did you get a BHO project working with VB yet, if so are you willing to share an example? I’m clueless in how to do it with VB…

Like

Brilliant example and presentation – everything works as promised. After loads of struggle in MSDN jungle, it’s like heaven. đŸ˜‰

Like

Hi,
I try this example but I have a problem. It don’t call setSite.. must it call automatically or i must call it somewhere??
thank you very much for your answer,
Valerio

Like

Hi;

When i try to compile this sample i got these errors. How can i manage i?

Error 1 error C2955: ‘ATL::CComObjectRootEx’ : use of class template requires template argument list
Error 2 error C2955: ‘ATL::CComCoClass’ : use of class template requires template argument list
Error 3 error C2955: ‘ATL::IConnectionPointContainerImpl’ : use of class template requires template argument list

Error 4 error C2504: ‘CProxy_IBrowserHelperEvents’ : base class undefined

Error 5 error C2955: ‘ATL::IObjectWithSiteImpl’ : use of class template requires template argument list

Error 6 error C2955: ‘ATL::IDispatchImpl’ : use of class template requires template argument list

Error 7 fatal error C1903: unable to recover from previous error(s); stopping compilation

Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.