VB6 Programmer's Introduction to COM
By now, you should have an idea of what COM is and what it can do for you, so it's time to wheel out the big guns. Microsoft Visual Basic can make a developer very productive when it comes to creating and using COM components. In fact, Visual Basic itself relies very heavily on COM technologies.
One of the advantages of using Visual Basic to create COM components is the ease with which it can be done. Visual Basic hides a lot of the plumbing needed to implement COM components and lets you focus on developing what your components will do, or what business functionality they will address.
The Visual Basic COM Players
Microsoft Visual Basic allows you to create a number of different COM-enabled projects, three of which we will be concentrating on in this book. First, there are ActiveX controls, which have a user interface associated with them. As a Visual Basic developer, you are probably most familiar with the ActiveX controls that are available as tools in your toolbox.
Also, if you go to Visual Basic's Project menu and select Components... (or just use Ctrl-T), you can see all the ActiveX controls that are registered on your local machine (that is, those that have entries in the system registry):
ActiveX controls generally have a .ocx file extension, as you can see if you look at the Location field in the previous screenshot.
The second kind of project we'll be looking at is the ActiveX DLL. These are COM-enabled files with a .dll extension, and they contain the COM components that you will find yourself using most often. Unlike their ActiveX control counterparts, components in ActiveX DLLs typically do not have user interfaces. Generally, they are made up of a class or a set of classes that are blueprints for the COM objects that you will create.
Thirdly, ActiveX EXEs are very similar to the ActiveX DLLs, except they are out-of-process servers, which means that they don't run in the same memory space as the application that calls them. By the same reasoning, ActiveX DLLs are often called in-process servers, because they do run in the same memory space as the application that calls them. Don't worry if some of these terms are unfamiliar to you at the moment; just understand that there is a difference, and I will have plenty to say about the advantages and disadvantages of in- and out-of-process servers later in the book.
Individually and collectively, these three different project types allow us to easily create reusable components with Visual Basic. Moreover, because these ActiveX components are built on COM we can use them with COM components irrelevant of language or container.
In Chapter 5, we'll create a simple ActiveX control consisting of two text boxes that our developer, Phil, might want use in his application. In Chapter 6, we'll look at how he can distribute COM objects across a network and we'll see the importance of ActiveX EXEs in achieving this. Finally, in Chapter 7 we'll see how Phil can easily provide multi-user support for his ActiveX DLLs.
Page 11 of 12