Microsoft COM (Component Object Model) technology in the Microsoft Windows-family of Operating Systems enables software components to communicate. COM is used by developers to create re-usable software components, link components together to build applications, and take advantage of Windows services. COM objects can be created with a variety of programming languages. Object-oriented languages, such as C++, provide programming mechanisms that simplify the implementation of COM objects. The family of COM technologies includes COM+, Distributed COM (DCOM) and ActiveX® Controls.
Microsoft provides COM interfaces for many Windows application programming interfaces such as Direct Show, Media Foundation, Packaging API, Windows Animation Manager, Windows Portable Devices, and Microsoft Active Directory (AD).
COM is used in applications such as the Microsoft Office Family of products. For example COM OLE technology allows Word documents to dynamically link to data in Excel spreadsheets and COM Automation allows users to build scripts in their applications to perform repetitive tasks or control one application from another.
The IRunningObjectTable interface manages access to the Running Object Table (ROT), a globally accessible look-up table on each workstation. A workstation's ROT keeps track of those objects that can be identified by a moniker and that are currently running on the workstation. When a client tries to bind a moniker to an object, the moniker checks the ROT to see if the object is already running; this allows the moniker to bind to the current instance instead of loading a new one.
The ROT contains entries of the form:
(pmkObjectName, pUnkObject)
The pmkObjectName element is a pointer to the moniker that identifies the running object. The pUnkObject element is a pointer to the running object itself. During the binding process, monikers consult the pmkObjectName entries in the Running Object Table to see if an object is already running.
Objects that can be named by monikers must be registered with the ROT when they are loaded and their registration must be revoked when they are no longer running.
The following example shows the display names of all the objects currently registered in the Running Object Table (ROT).
' ########################################################################################
' The following example shows the display names of all the objects currently registered in
' the Running Object Table (ROT).
' ########################################################################################
#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"
#INCLUDE "objidl.inc"
' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG
LOCAL hr AS LONG
LOCAL pbc AS IBindCtx
LOCAL pRot AS IRunningObjectTable
LOCAL pEnumMoniker AS IEnumMoniker
LOCAL pMoniker AS IMoniker
LOCAL pceltFetched AS DWORD
LOCAL pwszDisplayName AS WSTRINGZ PTR
' // Get a pointer to a bind context
hr = CreateBindCtx(0, pbc)
IF hr <> %S_OK THEN EXIT FUNCTION
' // Get a reference to the Running Object Table (ROT)
hr = pbc.GetRunningObjectTable(pRot)
IF hr <> %S_OK THEN EXIT FUNCTION
' // Get a pointer to the moniker enumerator
hr = pRot.EnumRunning(pEnumMoniker)
IF hr <> %S_OK THEN EXIT FUNCTION
' // Enumerate the monikers and retrieve the display name
DO
' // Fetch the next moniker
hr = pEnumMoniker.Next(1, pMoniker, pceltFetched)
IF hr <> %S_OK THEN EXIT DO
' // Get the display name
hr = pMoniker.GetDisplayName(pbc, NOTHING, pwszDisplayName)
IF hr <> %S_OK THEN EXIT DO
IF pwszDisplayName THEN
' // Display the name
? @pwszDisplayName
' // Free the server allocated string
CoTaskMemFree pwszDisplayName
END IF
' // Release the moniker reference
pMoniker = NOTHING
LOOP
#IF %DEF(%PB_CC32)
WAITKEY$
#ENDIF
END FUNCTION
' ========================================================================================