Session 1 COM Interoperability
Session Objectives <ul><li>Explain .NET components evolution from COM </li></ul><ul><li>Use COM components from .NET </li>...
Introduction <ul><li>In today’s world Business Logic resides in COM </li></ul><ul><li>With the evolution of .NET , COM pos...
COM <ul><li>COM facilitates language independent code re-use </li></ul><ul><li>COM components provided additional features...
COM <ul><li>The COM component needs to be registered in the Windows Registry </li></ul><ul><li>It turned out to be a great...
.NET -1 <ul><li>.NET is a component technology like COM </li></ul><ul><li>Issues like cross language inheritance are taken...
.NET -2 <ul><li>.NET code executes in an environment entirely managed by the CLR </li></ul><ul><li>This includes Garbage c...
Component handling in COM and .NET -1 <ul><li>COM exposes its classes and methods through interfaces </li></ul><ul><li>.NE...
Component handling in COM .NET-2 <ul><li>Metadata is embedded within an assembly </li></ul><ul><li>Interoperating between ...
Adding a reference <ul><li>To make use of a COM component in an  application, we just add a reference to the  Project </li...
Using the COM component <ul><li>After adding the reference, we can start using the classes within the COM component as if ...
Runtime Callable Wrapper <ul><li>The proxy that talks to the component is known as the RCW (Runtime Callable Wrapper) </li...
Runtime Callable Wrapper <ul><li>Client talking to the RCW - </li></ul>
Runtime Callable Wrapper <ul><li>The RCW assembly is automatically created by Visual Studio.NET in the applications direct...
Runtime Callable Wrapper <ul><li>The type information is Marshaled from COM types into .NET types and then written into th...
COM vs. .NET <ul><li>COM components manage their lifetime  whereas the CLR manages the lifetime in .NET </li></ul><ul><li>...
COM vs. .NET <ul><li>COM components return a memory pointer to an object, hence they must reside in the same memory locati...
COM vs. .NET <ul><li>COM components manage the lifetime by using reference counting </li></ul><ul><li>When this count reac...
COM vs. .NET <ul><li>The COM component created using .NET are destroyed by the CLR when the Reference count reaches zero <...
RCW management in .NET <ul><li>Graphical representation - </li></ul>
The TlbImp Utility <ul><li>Is used to convert a COM Type library into a .NET assembly </li></ul><ul><li>Syntax –  </li></u...
Accessing a .NET component from COM <ul><li>.NET provides a mechanism where COM  clients can call .NET components </li></u...
Assembly Registration Tool <ul><li>The command line tool to register or unregister is – </li></ul><ul><li>RegAsm.exe </li>...
COM Callable Wrapper <ul><li>The runtime generates another wrapper object </li></ul><ul><li>It is known as the CCW ( COM C...
COM Callable Wrapper <ul><li>The CCW acts as a proxy between the COM & .NET components </li></ul>
Lifetime of CCW <ul><li>The runtime creates exactly one CCW for a managed .NET component </li></ul>
The TlbImp Utility <ul><li>The TlbImp utility in action - </li></ul>
Upcoming SlideShare
Loading in …5
×

Session 1

344 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Session 1

  1. 1. Session 1 COM Interoperability
  2. 2. Session Objectives <ul><li>Explain .NET components evolution from COM </li></ul><ul><li>Use COM components from .NET </li></ul><ul><li>Explain the Runtime Callable Wrapper </li></ul><ul><li>Explain the COM Callable Wrapper </li></ul><ul><li>Discuss the Type Library conversion into Metadata </li></ul><ul><li>Use .NET components from COM </li></ul>
  3. 3. Introduction <ul><li>In today’s world Business Logic resides in COM </li></ul><ul><li>With the evolution of .NET , COM poses a problem of compatibility </li></ul><ul><li>The .NET runtime simplifies the complexities involved in compatibility </li></ul>
  4. 4. COM <ul><li>COM facilitates language independent code re-use </li></ul><ul><li>COM components provided additional features like IUnknown interface </li></ul><ul><li>COM component needs to be identified uniquely using a 128 bit GUID (Globally Unique Identifier) </li></ul>
  5. 5. COM <ul><li>The COM component needs to be registered in the Windows Registry </li></ul><ul><li>It turned out to be a great problem because Cross Language Inheritance is not possible using COM </li></ul>
  6. 6. .NET -1 <ul><li>.NET is a component technology like COM </li></ul><ul><li>Issues like cross language inheritance are taken care of, in .NET </li></ul>
  7. 7. .NET -2 <ul><li>.NET code executes in an environment entirely managed by the CLR </li></ul><ul><li>This includes Garbage collection and Security for a .NET application </li></ul>
  8. 8. Component handling in COM and .NET -1 <ul><li>COM exposes its classes and methods through interfaces </li></ul><ul><li>.NET exposes its classes and methods in an assembly using metadata and reflection </li></ul><ul><li>The type information of a COM component resides in an external Type Library file </li></ul>
  9. 9. Component handling in COM .NET-2 <ul><li>Metadata is embedded within an assembly </li></ul><ul><li>Interoperating between these two is a challenge </li></ul><ul><li>.NET achieves this by creating a proxy class for every COM component that the .NET client tries to access </li></ul><ul><li>It is the proxy that talks directly to the </li></ul><ul><li>component </li></ul>
  10. 10. Adding a reference <ul><li>To make use of a COM component in an application, we just add a reference to the Project </li></ul>
  11. 11. Using the COM component <ul><li>After adding the reference, we can start using the classes within the COM component as if it were a .NET component </li></ul>
  12. 12. Runtime Callable Wrapper <ul><li>The proxy that talks to the component is known as the RCW (Runtime Callable Wrapper) </li></ul><ul><li>It is a .NET assembly </li></ul><ul><li>The RCW takes care of type casting of data types apart from various other activities </li></ul>
  13. 13. Runtime Callable Wrapper <ul><li>Client talking to the RCW - </li></ul>
  14. 14. Runtime Callable Wrapper <ul><li>The RCW assembly is automatically created by Visual Studio.NET in the applications directory </li></ul><ul><li>The RCW does not contain any form of business logic </li></ul><ul><li>It has the type information of the elements contained within the COM component </li></ul>
  15. 15. Runtime Callable Wrapper <ul><li>The type information is Marshaled from COM types into .NET types and then written into the assembly </li></ul><ul><li>This type information is stored in the form of Metadata as it is a .NET assembly </li></ul><ul><li>This helps Intellisense in Visual Studio.NET </li></ul>
  16. 16. COM vs. .NET <ul><li>COM components manage their lifetime whereas the CLR manages the lifetime in .NET </li></ul><ul><li>COM components use interfaces whereas .NET clients use reflection to learn about the functionality of the object </li></ul>
  17. 17. COM vs. .NET <ul><li>COM components return a memory pointer to an object, hence they must reside in the same memory location throughout the lifetime of the object </li></ul><ul><li>.NET objects can shift between virtual and physical memory freely as either becomes more available, making optimum utilization of memory space </li></ul>
  18. 18. COM vs. .NET <ul><li>COM components manage the lifetime by using reference counting </li></ul><ul><li>When this count reaches zero the object of that component is destroyed </li></ul><ul><li>In .NET, the CLR manages the lifetime of the object </li></ul>
  19. 19. COM vs. .NET <ul><li>The COM component created using .NET are destroyed by the CLR when the Reference count reaches zero </li></ul><ul><li>Regarding the lifetime of RCW, only one copy of the RCW object is created no matter how many clients request the same COM component </li></ul>
  20. 20. RCW management in .NET <ul><li>Graphical representation - </li></ul>
  21. 21. The TlbImp Utility <ul><li>Is used to convert a COM Type library into a .NET assembly </li></ul><ul><li>Syntax – </li></ul><ul><li>TlbImp <COM Dll Name> / out:<Proxy Name> </li></ul>
  22. 22. Accessing a .NET component from COM <ul><li>.NET provides a mechanism where COM clients can call .NET components </li></ul><ul><li>Information of the .NET component needs to be registered in the Windows Registry </li></ul><ul><li>To register or unregister a .NET class with COM you must run a command line tool </li></ul>
  23. 23. Assembly Registration Tool <ul><li>The command line tool to register or unregister is – </li></ul><ul><li>RegAsm.exe </li></ul><ul><li>Syntax – </li></ul><ul><li>RegAsm/install <dotNETAssembly.dll> </li></ul>
  24. 24. COM Callable Wrapper <ul><li>The runtime generates another wrapper object </li></ul><ul><li>It is known as the CCW ( COM Callable Wrapper) </li></ul><ul><li>The CCW is same as the RCW, it bridges the gap between two environments </li></ul>
  25. 25. COM Callable Wrapper <ul><li>The CCW acts as a proxy between the COM & .NET components </li></ul>
  26. 26. Lifetime of CCW <ul><li>The runtime creates exactly one CCW for a managed .NET component </li></ul>
  27. 27. The TlbImp Utility <ul><li>The TlbImp utility in action - </li></ul>

×