As Coplien and others have
pointed out, defining a seaplane to be a kind-of-a boat and a kind-of-plane may
not be the most effective use of the inheritance feature in C++. This is
because we are dealing with state changes and inheritance is a static
relationship between classes. A more effective approach is to define a seaplane
as a class that dynamically delegates to class boat or plane, depending on the
state (i. e., whether it is airborne or water-borne). We run into similar
problems whenever we try to model anything that has state. Other examples
include idle, dialing and connected telephone lines, and (my favorite) space
shuttles that are sometimes rockets, satellites, gliders or land vehicles.
- Basic
Concepts
- Early v. late binding
- Static inheritance v. dynamic delegation
- Implementing dynamic
delegation in C++
- Using the dynamic_cast feature
- Problems with C++ casting
- The Ugly Approach: Inheriting Everything
- The Only Slightly Less Ugly Approach: Run Time Type Identification using
dynamic_cast
- What we really need but cannot have in C++:
Dynamic Delegation
- A brief introduction to IDispatch and the Automation feature.
-
Data Structures
-
The IDispatch Interface
-
The Dispatch Table
-
The BSTR (Basic String) Data Type
-
The Variant Data Type
-
DispParams
-
The Usual Approach to Implementing IDispatch: the MFC and ATL Wizards
- Implementing IDispatch
Manually
- IDL and type libraries
-
What is a Type Library and a TypeInfo Structure?
-
The IDL Syntax
-
Compiling IDL Files
-
Marshalling with IDL Keyword OleAutomation
- The role of Java and Visual Basic
-
Implementations Java and Visual Basic
-
Browsers
-
Microsoft Office Products
-
Implementing Your Own: Microsoft's Callable Interpreters
-
A General Strategy: Using COM for Java Clients and C++ Servers
-
Merits of COM: Local/Remote Transparency, Version Independence and Legacy Code
-
Merits of Java: Easy User Interfaces
-
J++ v. Sun's Standard Java: They Are Not Quite Synonymous!
- An Example: implementing the Space Shuttle in Java and C++
- The C++ Server
-
The IDL File
-
The C++ Implementation of IDispatch
-
Compiling and Linking
- The Java Client
-
Importing the Server
-
Instantiating the Shuttle Server Object
-
Making the Shuttle Object Dynamically Delegate to Objects Rocket, Satellite and Airplane as a function of Altitude and Previous State
Top
Home
Using ATL Controls to
Connect to Remote Servers
Normally controls are self-contained
and use COM to communicate with their local containers (e. g., browsers, Visual
Basic dialog boxes). To harness their full power, however, this article
explores several approaches to establishing remote connections with DCOM
Servers -- including other controls.
- The Easy
Approach: Connecting to Servers with Pipes, Sockets, and HTTP
- Automated Deployment and Registration with the Codebase Feature
- Connecting To Remote Servers
- Strategy #1: Connecting via Monikers and the Running Object
Table
- Strategy #2: Connecting to Class Factories by Automating the
Registration of Remote Servers
- Remote EXE Servers
- Remote Controls
- Implementing a Chat Program
Top
Home
Windows, Threads and the ActiveX Template Library
We
often take threads for granted, but Win32 imposes some very interesting
challenges when we consider memory managment and windows inside COM servers.
This article explains the different kinds of threads, when to use them, how to
create them, and, most importantly, how to shut them down gracefully when using
the ActiveX Template Library.
- Creating Threads
- Comparing Threads
- Worker Threads
- User Interface (UI)
Threads
- Hybrid Worker and UI
Threads
- Creating Windows for UI
Threads
- Thread Affinity and Windows
- Creating Child Windows for
Worker Threads
- Shutting Down Child Threads
- What happens to all those
kernel mode objects when the parent thread calls ExitProcess prematurely?
- The Romeo & Juliet
Syndrome: Does the window kill the thread or does the thread kill the
window?
- The MFC Approach
- Implementing the MFC
Approach in ATL
- C++ Objects v. Kernel
Objects: Who calls Delete?
- Beware of Nasty
Destructors that Call CloseHandle()!
Top
Home
MFC Template Containers and Serialization
This
three part article explains the subtle issues of using and serializing the MFC
Template Container classes. (Unfortunately, this can be very perilous for the
uninitiated.) We will examine Microsoft's strange approach to optimization and
iteration and propose some basic improvements (such as copy constructors) that
can be implemented in descendant classes. Lastly, this article compares the
Template MFC Containers with the Standard Template Library and the earlier
inheritance based containers. Of course, this article discusses vital issues
not found in any tutorial.
- An Overview of MFC Template Containers: Arrays,
Lists and Maps
- A Brief Review of C++ Templates
- Microsoft's Strangeness:
Extra Template Parameters
- The Recipe Example with
Lists, Arrays and Maps
- So what is Wrong with
Passing By Value?
- Pointer Containers v.
Object Containers
- Hash Functions and Function
Template Instances
- Iterating Over Arrays, Lists
and Maps
- So what is Serialization?
Introducing Classes CFile and CArchive
- The Rectangles and Ellipse
Example
- Strategy #1: The Easy Way
with No Pointers!
- Strategy #2: Accommodating
Pointers
- Serializing Scalars by
Deriving from CObject
- The Declare and Implement
Serial Macros
- Serializing Arrays, Lists
and Maps
- Don't Store Those
Pointers! Use the Serialize Elements Function
- Multiply Dimensioned
Containers
- Reconstructing Shared
Objects
- MFC Template Containers v.
MFC Inheritance Based Containers
- MFC Template Containers v.
Standard Template Library Containers
- MFC Containers and Win32
Threads
- Using Exceptions to
Implement const
Top
Home
Why COM?
The
typical textbook approach of using C++ to implement custom interfaces for COM
can make COM seem horribly complex to the beginner. This article explores the
merits and alternatives to COM server programming in C++ and explains why and
how to implement a function in COM.
- So What Problem was COM Designed to Solve, Anyway?
- The Internet Problem
- The Candidate Solutions
- The Language Approach:
Java
- The Legacy Approach: RPC
and IDL
- The Standard Approach:
CORBA
- The Microsoft Solution:
DCOM
- Examining the DCOM Approach
- Strategy #1: Abandon Code Reuse with Custom
Interfaces
- Strategy #2: COM Client Programming with Microsoft
Standard Interfaces
- Strategy #3: Abandon
Header Files with Automation
- Creating a Simple COM
Client/Server Application using Visual C++ V6
Top
Home
COM Client Programming in C++
The
typical textbook approach to learning COM with C++ is to immediately dive into
implementing custom COM servers as described in a previous article. Aside from the fact
this can be overwhelming, it abandons the key aspect of object-orientation:
code reuse. And lastly, one should not
ignore the obvious: before diving into writing your own server object, one
should, as a matter of general principle, examine what classes have already be
implemented for you. This article examines the basic aspects of COM client
programming in C++ and focuses on using classes already implemented for us.
- The Basics of COM Clients
- Basic Concepts
- 128 bit Globally Unique
Identifiers (GUIDs)
- Interface Identifies
(IIDs)
- Class Identiifers
(CLSIDs)
- Program Identifiers
(ProgIDs)
- Initializing COM
- So what is the problem
with the client using new and C++ constructors to create server objects?
What is the problem with casting from one ancestor to another?
- The usage counting
algorithm
- Using CoCreateInstance instead
- Using GetClassObject and IClassFactory::CreateInstance instead.
- Introducing the grand
ancestor: IUnknown.
- The Basic Approach
- Initializing COM
- Translating a ProgID to a
CLSID
- Calling CoCreateInstance
- Calling IUnknown::QueryInterface
- Performing your work
- Releasing your pointer
- Uninitialzing COM
- A Few COM Functions and Class
Implementations You can Use!
- Storing Objects
- IStorage and IStream
- ILockBytes
- Monikers
- What are they
- How to use monikers
- Moniker ancestor classes
- Implementing Drag &
Drop and the Clipboard with Universal Data Transfer (UDT)
- Fetching a moniker from
the clipboard
- Binding (dereferencing)
the moniker to create an object
- Copying the object
directly from the clipboard
- Saving and restoring the
object with structured storage
- COM Automation: What is
it?
- Example automation
clients
- ActiveState Perl
- Excel
- Visual Basic
- Developer Studio
- IDispatch
- GetIDsOfNames
- Invoke
- Implementing C++ IDispatch Clients
- The hard way
- The easy way using the
MFC Class Wizard
- Other useful classes of
objects that are implemented for you
- Web Browsers
- Java and Visual Basic Interpreters
- Mail
- Documents from Microsoft
Office
- Active Data Objects (ADO)
and OleDB
Top
Home