Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Knowledge Base > Code Library > Browser Helper Object (BHO) Sample


Reply
 
Thread Tools Display Modes
  #1  
Old 12-22-2002, 07:46 AM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default Browser Helper Object (BHO) Sample


A simple (when I say simple, I MEAN simple.. ) example of how to
attach a class object to each and every instance of Internet
Explorer, and Windows Explorer.

Here's a little background info on how BHOs work:

Each time a new instance of Explorer (whether it's Internet
Explorer or Windows Explorer) is loaded, it searches through a
specific part of the registry for BHOs. These are then loaded and
instantiated. Now, here's where it gets a bit compocated - since
Internet Explorer must load these objects, it must be able to
have a variable to store a reference at some point. In VB, if you
want a string, then you declare a String. With objects, you declare
the class type -
Code:
Dim oMyClass As Class1
What you're really doing is declaring a reference to the default
interface that class supports. A class' interface is it's properties,
methods and events, and their parameters. It's a description of
that class. Since all the BHOs may well have totally different
functions to perform, they may also have totally different
interfaces, and this causes Internet Explorer a problem. To over
come this problem, each BHO MUST implement a certain interface:
IObjectWithSite, which looks like this:
Code:
Private Sub IObjectWithSite_GetSite(ByVal priid As VBShellLib.REFIID, ppvObj As VBShellLib.VOID) ' End Sub Private Sub IObjectWithSite_SetSite(ByVal pSite As VBShellLib.IUnknownVB) ' End Sub
These interfaces are not built into VB, and we can't just declare
them as an empty class module, due to the inner workings of
VB. As such, we're reliant on Type Libraries - files that contain
interface definitions (amongst other things). I've included
VBShell.tlb, available from Edanmo's VB site.

So.. how do we attach to Internet Explorer? Well, when the
BHO is first loaded, SetSite will be called, and a reference to the
browser passed via pSite. All we have to do is store this
pointer, convert it into an InternetExplorer object (which uses
the IWebBrowser2 interface) and we're done.

There's a couple of other things on BHOs that you should know,
but for further reading I suggest these pages:
To make the extension included work, simply run the Register.reg
file, then open a new InternetExplorer. You should see a MsgBox
containing the URL of each link BEFORE Internet Explorer begins
navigating to it. To remove the BHO, just run Un-Register.reg.
Have a look inside the REG files to see which bits of the registry
Internet Explorer searches in.

Oh, one other point. The thing about BHOs (and all compiled
ActiveX DLLs for that matter) is that they all have to be uniquely
identified. This requires what's known as a CLSID (Class ID).
This is used when registering the BHO to Internet Explorer, and
if it changes, then your BHO won't load properly. As such, you
MUST have the Binary Compatibility option set on the BHO DLL.
Also, you CANNOT break the class' interface if you want to have
the same CLSID - once the interface changes, so must the CLSID.
I don't want to go into too much detail, but I suggest that you
read Thinker's magnificent tutorial on COM and interfaces, to be
found here:
Enjoy
Attached Files
File Type: zip bho sample.zip (28.3 KB, 1920 views)
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->