Wednesday, July 2, 2008
How can we use .NET components in COM?Twist: What is CCW (COM callable wrapper)? Twist: How do we ensure that .NET component is compatible with COM?
.NET components can not be used in straight forward way with COM. You will need to create CCW in order that COM components communicate with .NET assemblies. Other way to create CCW is by using InteropServices attributes. Here interfaces are created automatically. Following are different types of attributes: -None: No class interface is generated for the class. This is default setting when you do not specify anything. -AutoDispatch: Interface that supports IDispatch is created for the class. However, no type information is produced. -AutoDual: A dual interface is created for the class. Type information is produced and made available in the type library. Below in the source code we have used the third attribute. Imports System.Runtime.InteropServices _ Public Class ClsCompliant End Class Other than class attributes defined up there are other attributes with which you can govern other part of assembly. Example “GuidAttribute” allows you to specify the GUID, “ComVisibleAttribute” can be used to hide .NET types from COM etc. -Once .NET assembly is created using either interface or using Interopservices method we need to create a COM type library using Type library export tool [Tlbexp (AssemblyName)] -The final thing is registering the CCW in registry using regasm tool. Regasm AssemblyName[Options] and that's it.
Labels:
ASP,
C#,
General,
interview questions,
Visual Studio