System and Application Softwares
Microsoft Windows, Azure and Office Suite
Microsoft COM, OLE and Active Technologies
This topic discusses Microsoft COM, OLE, and Active Technologies. These are the technologies that comprise Microsoft's component strategy, and they are the interprocess communication methods of choice when building applications for Windows.
COM is the Microsoft Component Object Model, which is the basic plumbing for all of Microsoft's component software strategy. COM includes features that enable components to be activated and used locally or remotely across a network. COM also provides for runtime discovery of a server's capabilities and lifetime management through the IUnknown interface.
OLE is the portion of Microsoft's component software strategy that enables applications to integrate document-like applications. Examples of applications that use OLE are Word, Excel, and Visio. OLE includes a number of technologies, such as drag and drop, embedding, and structured storage.
Active Technologies, evolving many of the original OLE technologies, enable software components to interact with one another in a networked environment. Active technologies can be used to create applications that run on the desktop or the Internet. Active technologies include both client and server technologies, including the following:
COM is the fundamental "object model" on which ActiveX Controls and OLE are built. COM allows an object to expose its functionality to other components and to host applications. It defines both how the object exposes itself and how this exposure works across processes and across networks. COM also defines the object's life cycle.
Fundamental to COM are these concepts:
COM objects are much like instantiated C++ classes. In fact, COM was designed with C++ programmers in mind. It supports encapsulation, polymorphism, and reusability.
However, COM was also designed to be compatible at the binary level and therefore has differences from a C++ object. As a programmer, you are aware that compiled programming languages such as C, C++ etc are machine-dependent. As a binary object, a COM object concerns itself with how it interfaces with other objects. When not used in the environment of its creator, an interface is exposed that can be seen in the non-native environment. It can be seen because it is a binary object and therefore not machine-dependent. This does not require the host environment or an interacting object to know anything about the COM object. When the object is created in the womb of its mother application, COM does not concern itself with how that object interacts within it. This interaction is between the mother application and the child object. When the object interacts with the rest of the world, however, COM is concerned about how to interface with that object.
It is important to note that COM is not a programming language; it is a binary standard that enables software components to interact with each other as objects. COM is not specific to any particular programming language. COM can work with any language that can support the binary layout of a COM object. It is a programming model to facilitate the programmability of this standard.
COM objects consist of two types of items: properties and methods.
COM objects each have a common interface. No matter what they do, COM objects all have to implement the IUnknown interface. This interface is the main interface for all others and is the base class from which all other COM interfaces are derived. The IUnknown interface has the following member functions:
Each object implements a vtable. A vtable is nothing more than an array of pointers to member functions implemented in the object, see the following figure:
This vtable is shared between all the instances of the object also maintaining the private data of each object. A client application evokes an instance of the interface and gets a pointer to a pointer that points to the vtable. Each time a new interface to the object is instantiated, the reference count of objects is incremented with AddRef(). Conversely, each time a reference is destroyed, the reference counter is decremented with Release(). Once the reference count is zero, the object can be destroyed. In order to see what interfaces an object supports, you can use QueryInterface().
COM objects are never directly accessed. COM objects are always accessed through a pointer to an interface exposed by the object. The QueryInterface(REFIID riid, void **ipv) function takes a reference to an interface identifier (riid) and a void pointer. The REFIID is a 128-bit unique ID that identifies the interface you are retrieving. Notice the double indirection on the pointer: **ipv. The ipv pointer is where the pointer to the interface you are trying to retrieve is stored. Consider this code fragment:
IAnyInterface* pAny = NULL;
HRESULT hr = pUnknown->QueryInterface(IID_IAnyInterface, (void**)&pAny);
pUnknown is a pointer to the object's IUnknown interface. DoAnyObjectWork() is the member function you want to use to perform some work. You access that function through the pointer to that object's interface pAny.
To understand COM (and therefore all COM-based technologies), it is crucial to understand that it is not an object-oriented language but a standard. Nor does COM specify how an application should be structured. Rather, COM specifies an object model and programming requirements that enable COM objects (also called COM components, or sometimes simply objects) to interact with other objects. These objects can be within a single process, in other processes, and can even be on remote computers. They can be written in different languages, and they may be structurally quite dissimilar, which is why COM is referred to as a binary standard; a standard that applies after a program has been translated to binary machine code.
The only language requirement for COM is that code is generated in a language that can create structures of pointers and, either explicitly or implicitly, call functions through pointers. Object-oriented languages such as C++ and Smalltalk provide programming mechanisms that simplify the implementation of COM objects, but languages such as C, Java, and VBScript can be used create and use COM objects.
COM defines the essential nature of a COM object. In general, a software object is made up of a set of data and the functions that manipulate the data. A COM object is one in which access to an object's data is achieved exclusively through one or more sets of related functions. These function sets are called interfaces, and the functions of an interface are called methods. Further, COM requires that the only way to gain access to the methods of an interface is through a pointer to the interface.
Besides specifying the basic binary object standard, COM defines certain basic interfaces like IUnknown that provide functions common to all COM-based technologies, and it provides a small number of functions (also known as COM sytem APIs, such as CoInitialize etc) that all components require. COM also defines how objects work together over a distributed environment and has added security features to help provide system and component integrity.
© 2019 Digcode.com. All rights reserved.