Introduction
How can we use COM Components in .NET?
.NET components communicate with COM using RCW (Runtime Callable Wrapper). Following are the ways with which you can generate RCW:
1.Adding reference in Visual Studio.net. See figure below (Adding reference using
VS.NET 2005). Wrapper class is generated and placed in the "BIN" directory.
2.Using Type library import tool. Tlbimp.exe yourname.dll.
-Using interopservices.System.runtime.Interopservices namespace contains class TypeLib Converter that provides methods to convert COM classes and interface in to assembly metadata.
-Make your custom wrappers. If your COM component does not have type library then the only way to communicate is writing custom wrappers. That means communicating directly with COM components.
We have developed the COM wrapper do we have to still register the COM?
Yes
How can we use .NET components in COM?
.NET components cannot be used in a straightforward way with COM. You will need to create CCW in order that COM components communicate with .NET assemblies.
How many types of Transactions are there in COM + .NET?
5 transactions types can be used with COM+. Whenever an object is registered with COM+, it has to abide either to these 5 transaction types.
Disabled: - There is no transaction. COM+ does not provide transaction support for this component.
Not Supported: - Component does not support transactions. Hence even if the calling component in the hierarchy is transaction enabled this component will not participate in the transaction.
Supported: - Components with transaction type support will be a part of the transaction. This will be only if the calling component has an active transaction. If the calling component is not transaction enabled this component will not start a new transaction.
Required: - Components with this attribute require a transaction i.e. either the calling should have a transaction in place else, this component will start a new transaction.
Required New: - Components enabled with this transaction type always require a new transaction. Components with required new transaction type instantiate a new transaction for themselves every time.
How do you do object pooling in .NET?
COM+ reduces overhead by not creating object from scratch. So in COM+ when object is activated it’s activated, from pool and when it has deactivated it’s pushed back to the pool. Object pooling is configures by using the “ObjectPoolingAttribute” to the class.
ObjectPooling(MinPoolSize := 2, MaxPoolSize := 5, CreationTimeout := 20000)>
Public Class testingclass
Inherits ServicedComponent
Public Sub DoWork()
' Method contents go here.
End Sub
End Class
Above is a sample code, which has the “Object Pooling” attribute defined. Below is a sample code, which uses the class.
Public Class App
Overloads Public Shared Sub Main(args() As String)
Dim xyz As New TestObjectPooling()
xyz.doWork()
ServicedComponent.DisposeObject (xyz)
End Sub
End Class
Above is a sample code, which uses the object pooled object. Note the Dispose Object () This ensures its safe return to the object pool.
What are types of compatibility in VB6?
There are three possible project compatibility settings:
• No Compatibility
• Project Compatibility
• Binary Compatibility
No Compatibility
With this setting, new class ID’s, new interface ID’s and a new type library ID will be generated by VB each time the ActiveX component project is compiled. This will cause any compiled client components to fail (with error 429!) and report a missing reference to the 'VB ActiveX Test Component' when a client project is loaded in the VB IDE.
Use this setting to compile the initial release of a component to other developers.
Project Compatibility
With this setting, VB will generate new interface ID’s for classes whose interfaces have changed, but will not change the class ID’s or the type library ID. This will still cause any compiled client components to fail (with error 429!) but will not report a missing reference to the 'VB ActiveX Test Component' when a client project is loaded in the VB IDE. Recompilation of client components will restore them to working order again.
Use this setting during the initial development and testing of a component within the IDE and before the component is released to other developers.
Binary Compatibility
VB makes it possible to extend an existing class or interface by adding new methods and properties etc. and yet still retain binary compatibility. It can do this, because it silently creates a new interface ID for the extended interface and adds registration code to register the original interface ID but with a new Forward key containing the value of this new interface ID. COM will then substitute calls having the old ID with the new ID and hence applications built against the old interface will continue to work (assuming the inner workings of the component remain backward compatible!). With this setting, VB will not change any of the existing class, interface or type library ID’s, however in order that it can do so, VB requires the project to specify an existing compiled version that it can compare against to ensure that existing interfaces have not been broken
I've been workin in microsoft technologies for more then 7 years and worked on Web and windows based application.I've been working on Clasic ASP,ASP.Net,C#,Javascript,HTML,SQL server and currently exploring C#3.5 and WFC.