.net components in com, DOT NET Programming

How can we use .NET components in COM

.NET components can't be used in straight forward way with the COM. You will require to create CCW in order to communicate COM components  with .NET assemblies. Following are some of the different approaches to implement it :-

1)Explicitly declare interfaces

Public Interface ICustomer

Property CustomerName() As String

Property CustomerCode() As String

Sub AddCustomer()

 End Interface

Public Class Customer

 Implements ICustomer

Private PstrCustomerName As String

Private PstrCustomerCode As String

Public Sub AddCustomer() Implements ICustomer.AddCustomer Try

 ' addin of database code can go here

Catch ex As Exception

Throw ex

 End Try

End Sub

Public Property CustomerCode() As String Implements

ICustomer.CustomerCode

Get

 Return PstrCustomerCode

 End Get

Set(ByVal value As String)

PstrCustomerCode = value

End Set

End Property

Public Property CustomerName() As String Implements ICustomer.CustomerName

Get

Return PstrCustomerName

 End Get

Set(ByVal value As String) PstrCustomerName = value

End Set

End Property

 Public Sub New()

End Sub

End Class

The above customer class is going to be used by COM components so all the properties and methods are declared in interface and implemented in the customer class.Customer Name.Customer Code &  AddCustomer are Ist declared in ICustomer & then implemented in the Customer Class. Please Note that the class must have a default constructor.

2)The second way to generate  CCW is by using InteropServices attributes. In this interfaces are created automatically.

 Following are the different type of class attributes :

None:-No class interface is generated for  class. This is the default setting when you do not specify anything.

AutoDispatch :- Interface that supports IDispatch is created for class. However, no type information is generated.

AutoDual :- A dual interface is created for the class. Type information is generated and made available in the type library.

Below are 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 some other attributes with which you can govern other part of  the assembly. For Example "GuidAttribute" allows you to specify the GUID, "ComVisibleAttribute" can be used to hide .NET types from COM etc.

a)When  .NET assembly is created using either interface or by using interopservices method we need to create a COM type library using Type library export tool.

Tlbexp (AssemblyName)

b)The final thing is registering the CCW in registry by using regasm tool.

regasm AssemblyName [Options]

c)Finally refer the TLB in your COM IDE Below is figure showing VB6 IDE referencing the DLL

500_.NET components in COM.png

Posted Date: 9/21/2012 7:23:35 AM | Location : United States







Related Discussions:- .net components in com, Assignment Help, Ask Question on .net components in com, Get Answer, Expert's Help, .net components in com Discussions

Write discussion on .net components in com
Your posts are moderated
Related Questions
Project Description: I am seeking some automated trading software for the given strategy, I am using Omnesys Nest trader Step 1: Buy one share at current market price (ex:

What are abstract classes? The features of the abstract class are as follows:- 1.     You can not create an object of the abstract class. 2.     The Abstract class is des

Project Description: Simple task on analysis svn and github .NET, PHP, Engineering, Software Architecture

Develop Outlook Add-In for all versions I need simple code for Outlook(express,2003,2007,2010,2013) Add-In with functionality to repeatedly send CC to the specified email(s), th

What is garbage collection? Explain the difference among garbage collections in .NET 4.0 and earlier versions. Garbage collection stops memory leaks during execution of pro

I have the project that takes screen shots and saves in the specific folder.(eg.Screen0001) but the problem is that if i close application and run it again then it replace the exis

Web Based Inventory Management System Project Description: I need a build in software which has the subsequent features, if anybody has ready to use web based application, pl

Prepare .NET TWAIN application to control digital imaging sensor Project Description: We are seeking somebody to create a .NET TWAIN application which will activate a digital

Create a Calculator application using Web Form with the following functions: 1.  Add 2.  Minus 3.  Multiply 4.  Divide Each of the above has to be a Web Service

Explain the concept of destructor? A destructor is a special method for a class and is requested automatically when an object is finally destroyed. The name of the destructor i