175
Using Visual Basic 6
with Visual Basic .NET:
COM Interop
This chapter focuses on making your Visual Basic 6 and Visual Basic .NET
applications work together. The mechanism that makes interoperability
between the two products possible is known as COM interop. We’ll start by
looking at the various ways you can create or use existing components that
communicate across COM and .NET component boundaries. We’ll also show
you how to debug across calls between Visual Basic 6 and Visual Basic .NET
authored components. Finally, we’ll discuss the role of binary compatibility in
Visual Basic .NET.
If you’ve been creating multitiered applications using Visual Basic 6, your
application has likely evolved into a large system spanning multiple compo-
nents. Let’s say, for example, that you have an application composed of a Visual
Basic standard EXE front end containing ActiveX controls talking to a middle-
tier Visual Basic DLL. The Visual Basic DLL in turn talks to a back-end SQL
Server database. Upgrading such an application to Visual Basic .NET in one
shot is nearly impossible. This is where COM interop swoops in to save the day.
COM interop allows you to upgrade one component at a time while keep-
ing the system alive. For example, you can upgrade your Visual Basic 6 middle-
tier component to Visual Basic .NET independently of the user interface (UI)
C
0
9
6
1
5
8
7
x
.
f
m
P
a
g
e
1
7
5
T
h
u
r
s
d
a
y
,
N
o
v
e
m
b
e
r
1
5
,
2
0
0
1
3
:
3
3
P
M
176
Part II Upgrading Applications
component. Once you have tested your new Visual Basic .NET component
with your Visual Basic 6 UI client, you can update the client to take advantage
of the new Visual Basic .NET server component. At a later date you may
decide to upgrade your Visual Basic 6 client components to Visual Basic .NET
components. An ActiveX control vendor may offer a .NET upgrade to your
favorite ActiveX control, leading you to replace all ActiveX versions of the con-
trol in your application with the .NET version. Eventually your entire syste