Updated 2018-04-28 04:51:47 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]
FrontPage.Editor.Document
Word.Document (note that WordPad is ''not'' a COM server)
InternetExplorer.Application
Excel.Application
Excel.Application.8
PDF.PdfCtrl.1
Word.Application
DSOleFile.PropertyReader

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

Wikipedia
COM chapter
from BOOK Tcl Programming for Windows
TclScript
COM-aware
COMet
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
COSH
OLE Object Viewer
optcl
Another Tcl interface to COM
TclBridge
allows Tcl to call COM objects and vice-versa. Very powerful, lots of options.
tcom
included in recent ActiveTcl releases, offers both client and server COM functionality.
TWAPI COM support
describes TWAPI's COM capabilities.
CAWT
Tcl interfaces to Microsoft Office and other applications using COM.