Introduction
This web-based tutorial will guide you through a tour of the Microsoft Component Object Model (COM) from the perspective of Visual Basic. It is not intended to be a comprehensive coverage of VB COM but an introduction. Our goals are the following:
To help you understand the motives behind COM, and why it has evolved to be the way it is.
To introduce you to object-based programming in general and COM programming in particular, all from the perspective of VB.
To present one of the most important concepts in COM, that of interfaces and interface-based programming
To look behind the scenes of VB and learn about GUIDs, IDL, type libraries and the registry.
To debunk the myth that COM programming is hard.
We assume that you are here because you are already motivated to learn about VB COM. If so, click here to setup your tutorial environment, and then you'll be ready to start! On the other hand, if you would like a little background on the motivations behind COM, continue reading below.
Motivation
Why COM?
COM was originally designed to enable objects to communicate with one another, objects written in different languages and running in different processes. If you stop and really think about this, COM solves a very difficult problem. Firstly, languages such as Visual Basic, C++ and Java have radically different run-time environments, type systems, parameter-passing mechanisms and object formats. Finding a common yet powerful object-oriented framework is not a trivial task. Secondly, in order for processes to communicate, data must be passed back and forth across address space boundaries (marshaled) in a synchronized manner. The calling object needs to block while it awaits completion of the call, and the callee object may need to queue up incoming calls as it completes the current one.
Thus, the first benefit of COM is that it enables the creation of plug-and-play software components. The power of this approach is readily apparent in Visual Basic itself, with its extensible collection of user-interface controls.
Like the object-oriented languages on which it is based, COM was also designed to support the evolution of software components. We all know that software evolves, both in terms of bug fixes and functionality. The question is how best to minimize the impact of change in an existing system. COM's solution is based on a strict adherence to the notion of interface-based programming. As you will see later in this tutorial, interfaces are simply a collection of method signatures. However, software designs based on immutable interfaces are better able to evolve since object implementations can change while remaining backward compatible with existing code. This is the second major benefit to be gained from using COM.
Finally, COM and its infrastructure enable the straightforward construction of distributed applications. COM objects interacting on the same machine can be moved to different machines without any coding changes! This greatly simplifies the development of multi-tier applications, especially when combined with other COM-based technologies such as MTS (Microsoft Transaction Server). Previously known as DCOM (Distributed COM), support for distributed computation is now considered an essential feature of COM and thus no longer carries a separate moniker.