Updated 2014-07-21 04:41:42 by APN

Microsoft's Component Object Model, or COM, a component of Windows, enables software components to communicate.

Disambiguation  edit

Serial Ports on Windows
MS-DOS-style serial-line devices are also called COM ports

Description  edit

Many popular Windows applications expose a COM automation interface, which allows external programs to launch and control them.

Alex Martelli: "COM-related technologies seem mostly pretty good, except for the little detail that they're often huge, rambling, and full of redundancies and pitfalls -- this goes for the object model of WMI just as well as for those of MS Office applications."

At various times, steveo, stever, CL, and others have worked on DCOM.

[Explain relation between COM and WSH.]

Example: ProgID  edit

The starting point to an application's COM automation interface is through its programmatic identifier (ProgID).

Here are a few example ProgID's, any of which might be used in, for instance, tcom with
set application [::tcom::ref createobject $ProgID]

Netscape.Network.1 [http://developer.netscape.com/docs/manuals/communicator/OLE/ole2net.htm]
Word.Document (note that WordPad is ''not'' a COM server)

Finding Available COM Objects  edit

In How do you find all ActiveX servers? ,comp.lang.tcl ,2001-10-19, Chin Huang provides the following code to search the Windows registry for available COM objects, and prints their ProgID:
package require registry

set classesRootKey "HKEY_CLASSES_ROOT\\CLSID"
foreach clsid [registry keys $classesRootKey] {
    set clsidKey "$classesRootKey\\$clsid"
    set progIdSubKey [registry keys $clsidKey "VersionIndependentProgID"]
    if {[llength $progIdSubKey] > 0} {
        set progId [registry get "$clsidKey\\$progIdSubKey" ""]
        puts $progId

COM Constants  edit

One of the eternal puzzles of COM work is how to find the right constants. Mark Hammond packaged up his insight on COM's constants into a Python module called win32com.clients.constants. Presumably we could, given enough motivation, do the same for Tcl, or at least render the code into human-readable direction.

The section titled How to Obtain Built-In Constant Values for an Office Application on the page How one discovers the API for a COM-exporting application explains how to do this using tcom.

Structured Storage  edit

COM Structured Storage provides file and data persistence in COM by handling a single file as a structured collection of objects known as storages and streams. Pat Thoyts' tclstorage provides access to Structured Storage from Tcl.

Pat also has an "OLE Application automation" [1]

See Also  edit

COM chapter
from BOOK Tcl Programming for Windows
a COM Explorer for Tcl, which relies on tcom, facilities discovery and interactive programming of COM objects.
COM Tree
another COM inspector
COM Events
COM gateway extension
COM on! - a tiny web browser
OLE Object Viewer
Another Tcl interface to COM
allows Tcl to call COM objects and vice-versa. Very powerful, lots of options.
included in recent ActiveTcl releases, offers both client and server COM functionality.
TWAPI COM support
describes TWAPI's client side COM capabilities.