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
————————————————————–
————————————————————–
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?
LikeLike
no, you would need the BHO installed first to make the BHO do any sort of redirecting
LikeLike
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.
LikeLike
Hey,
Do you know how to make a BHO in vb.net? I’ve searched anywhere and can’t find any information on it.
LikeLike
well, the first BHO’s I made way back in the day were in VB 6. You can make a BHO in .NET as well…
http://www.15seconds.com/issue/040331.htm
that example is in C#, but you should be able convert it over to VB.net pretty easily
LikeLike
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?
LikeLike
Hi Steve – everyone should definitely follow the text version. Once I did that, it all works fine. Thanks for the lesson.
LikeLike
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…
LikeLike
where do the methods go?
LikeLike
Brilliant example and presentation – everything works as promised. After loads of struggle in MSDN jungle, it’s like heaven. đŸ˜‰
LikeLike
ExDisp.h
LikeLike
Great example. How would you go about using the BHO to interact with the IE GUI (say, add an image to a toolbar)?
Conrad
LikeLike
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
LikeLike
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
LikeLike
Yes, some code is missing.
Included header is also:
#include , not maybe it’s now obselete.
And fix the errors ‘use of class template requires template argument list’ by adding right arguments:
CComQIPtr WebBrowser2Ptr;
CComPtr spCP;
CComQIPtr m_CPCptr;
Reference: http://msdn.microsoft.com/en-us/library/Bb250436.aspx#bho_writing
LikeLike