COM Facts
Prior to .NET, Windows development was done in an unmanaged environment using COM technologies or the Windows API. COM focused on creating components called COM components. For example, Microsoft Word is an application, but also a COM component. This means that other applications can access the Microsoft Word interface using COM. COM components allow some level of language independence. For example, a COM component written in C++ can be used in Visual Basic.
COM and .NET may have many similarities, but they also have many differences. The following table contrasts COM and .NET.
| COM | .NET |
| Clients of COM objects must manage the lifetime of those objects. | In .NET, the Common Language Runtime (CLR) manages the lifetime of objects in its environment. |
| Clients of COM objects discover whether a service is available by requesting an interface that provides that service and by getting back a pointer to that interface. | Clients of .NET objects can obtain a description of an object’s functionality using reflection. This refers to the fact that a .NET assembly is self-describing. |
| COM (and any unmanaged program) relies on objects remaining stationary in memory, otherwise, any pointer in that code is invalidated. | .NET objects reside in memory managed by the CLR execution environment. The execution environment can move objects around in memory for performance reasons and update all references to the objects it moves. |
.NET provides a way to interact with COM components.
- COM interop requires the existence of a Primary Interop Assembly.
- The Primary Interop Assembly typically contains no code, just MetaData that describes existing COM types.
- Generally, the Primary Interop Assembly is provided by the vendor of the COM component.
- Visual Studio .NET will generate a Primary Interop Assembly when a reference to a COM component is added if a Primary Interop Assembly has not already been created.
- Primary Interop Assemblies can also be created using Tlbimp.exe.
- In order to allow managed .NET components to communicate with unmanaged COM components .NET will create a Runtime Callable Wrapper (RCW).
- The RCW is a .NET class that acts as a proxy to the COM object and handles the complexities of COM interop.
- The .NET client calls methods from the RCW in order to interact with the COM component.
The following diagram shows how COM and .NET interact.
Digg it | Save to del.icio.us | Netscape | Reddit | Stumble It!
- - - - - S P O N S O R I N G A D V E R T I S M E N T - - - - -