Introduction to COM Automation

This article is definitely a work in progress at the moment. This article will be written for C++ Programmers but it might be helpful for developers using other languages also. My intent is to focus on just Automation but much of Automation overlaps with ActiveX Controls. Automation, though, is much less complicated than ActiveX Controls.

The following COM Automation introduction is intended to explain the basics of Automation. I have a sample server and client that provides the details. The sample cannot do anything practical since it only implements the IUnknown interface. See Sequential Stream Server. I assume you have at least heard of the IUnknown interface but I will explain a bit about it.

Concepts

Something that I think is confusing is that the term "interface" is used by Microsoft documentation and articles with two general definitions. Sometimes the term is used to refer to generic communication but in the context of COM and ActiveX it is usually used to refer to interfaces that work in a manner that complies with the standard defined by COM and ActiveX.

IUnknown Interface

Since COM and related facilities are intended to be used from multiple development environments their design is intended to be relatively independent of C and C++. Therefore the mechanism  for communication must be relatively independent. COM servers and clients communicate with each other through COM using interfaces. All methods and properties of an object must be part of an interface. The IUnknown interface is a standard interface that is always required. Just as the C and C++ compilers know that for programs ("console programs" ) that comply with the standard for the languages, execution should begin in the "main" function, COM knows to establish communication with a server using the IUnknown interface.

EXE and DLL Files For Servers

Automation servers can be implemented in either an EXE or a DLL. This is a relatively minor detail but the Microsoft documentation and articles seem to trivialize the details to the extent that the differences (in my opinion) is not made clear in the Microsoft documentation and articles. So the following is a summary of the differences that I am aware of. The most important is the InprocServer32 and LocalServer32 registry keys since their relevance to EXE and DLL files seem to be less clear in the Microsoft documentation and articles than I think they should be.

DLL EXE Description
InprocServer32  (32-bit)
InprocServer (16-bit)
LocalServer32 (32-bit)
LocalServer (16-bit)
Specifies the path and filename for the DLL or EXE
DllRegisterServer and
DllUnregisterServer
RegServer and
UnregServer (options)
Self-registration and Self-unregistration of the server in the registry
None CoInitializeEx
or CoInitialize
COM Initialization

The RegServer and UnregServer options are specified on the command-line for EXEs. Typically they are prefixed with either a '-' or a '/' and usually either is acceptable.

For COM Initialization, OleInitialize can be used in an EXE if initialization is required for compound documents (not beginner stuff).

COM Initialization For Local Servers

Local servers (executables) must initialize COM using CoInitializeEx or CoInitialize. The concurrency model is also determined by these functions.


See my Visual C++ Programmer Stuff page for more C++ stuff.