Chapter 3 -- COM Threading Models

[Previous] [Next]

Chapter 3

Microsoft Visual Basic has made its reputation as a well-insulated Microsoft Windows programming language. The Visual Basic programmer does not have to be concerned about many of the fundamental aspects of Windows programming, such as creating windows programmatically, understanding message queues, constructing the required Windows application message loop for retrieving messages from the application's message queue, and dispatching messages to the target window that contains a callback function for handling events intended for its window. At its lowest level, Windows programming is available to users in the form of a large set of C language functions packaged in various libraries known as the Windows application programming interface (API). Despite the benefits of C, programming Windows in this language requires implementation of all the items I mentioned above, which are of no concern to the Visual Basic programmer. If you need a reminder of what programming Windows involves, pick up a copy of Programming Windows by Charles Petzold (5th ed., Microsoft Press, 1999).

In short, programming Windows in C is an arduous task. Using Visual Basic to program Windows, on the other hand, is gratifying because results are almost instantaneous. As you know, the benefits do not stop there. If, for some reason, the core functionality available in Visual Basic does not meet your needs, you can extend an application by incorporating Windows API functions, by integrating external functions from third-party DLLs, or by embedding components that accomplish some amazing feats, such as 3-D charting, data binding, and so forth. Prior to Visual Basic 5, components could be developed only in C or C++. Therefore, it was the C/C++ developer's responsibility to build components that functioned properly in Visual Basic.

But times have changed—Visual Basic 5 leveled the playing field to the Visual Basic programmer's advantage. Now that Visual Basic is heavily peppered with Microsoft ActiveX-based and COM-based technologies, Visual Basic is no longer just a Windows graphical user interface (GUI) application programming language. Version 5 added a long list of enhancements—for example, the ability to create ActiveX controls, documents, and servers. Visual Basic 6 picked up the torch by including further enhancements that allow the programmer to create Internet-based components seamlessly. The point is that along with these new benefits, the responsibility shifts to the Visual Basic programmer to understand the various contexts in which components developed in Visual Basic can be applied.

All design patterns described in this book are implemented in the ActiveX and COM technologies furnished with Visual Basic. As I've mentioned, the reason for design patterns is to produce reusable solutions for recurring problems, so why limit those solutions to Visual Basic when you can take advantage of ActiveX as a vehicle for transporting these solutions to various programming languages, environments, and operating systems? The intention of this chapter is to make you aware of one of the features of COM that will help you develop these solutions: the threading aspects of COM on a Win32 operating system. Understanding how COM functions in this environment will help you comprehend the impact on system performance and behavior that results from the decisions you make when developing ActiveX components in Visual Basic. To this end, I will give you a brief overview of Win32 fundamentals. This overview is followed by a discussion on COM threading models, with in-depth coverage of the areas supported by Visual Basic and light coverage of the remaining areas. For a detailed discussion about COM, refer to the following books: Essential COM by Don Box (Addison-Wesley, 1998), and Inside Distributed COM by Guy Eddon and Henry Eddon (Microsoft Press, 1998).



Microsoft Visual Basic Design Patterns
Microsoft Visual Basic Design Patterns (Microsoft Professional Series)
ISBN: B00006L567
EAN: N/A
Year: 2000
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net