.net components in com, DOT NET Programming

Assignment Help:

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


Related Discussions:- .net components in com

Title..case statement, Design an interface and add code to command buttons ...

Design an interface and add code to command buttons using case statement, to find coursework to be calculated using formula 0.6*1/6*total Mark

Explain the architecture of ado.net in brief, Explain the architecture of A...

Explain the architecture of ADO.NET in brief. AD0.NET having of two fundamental components: The DataSet, which is disconnected from the data source and does not require to k

Script for auto seating poker, Script for auto seating poker Project Des...

Script for auto seating poker Project Description: Not just like that though. I need a similar program that can scan during poker lobbys (pokerstars, ipoker, full tilt and on

Connect my marketplace website with stripe/connect, Project Description: ...

Project Description: I am trying to connect my marketplace website with Stripe/connect. I have 5 or 6 scripts already written that just need to be adjusted so they will work: 2

Gmail, how make the google sign up page?

how make the google sign up page?

Does a web service have state, Does a Web service have state? The Web s...

Does a Web service have state? The Web services do not have any method to maintain state. Though, it can access ASP.NET objects, such as application and session if they extend

Perform arithmetic operations - c# program, Perform Arithmetic Operations -...

Perform Arithmetic Operations - c# Program Hello, i didn't find the correct way of using arithmetic operations in c#. I am beginner for this language. Please suggest me some e

I want simple code for outlook, I want simple code for Outlook (express,200...

I want simple code for Outlook (express,2003,2007,2010,2013) Add-In with functionality to routinely send CC to the specified email(s), this system should have -Code for every th

We need programmers and accountants, We need programmers and accountants ...

We need programmers and accountants Skills required are .NET, C# Programming, Graphic Design, Commercials, Software Architecture

How do i force the dispose method to be called automatically, How do I forc...

How do I force the Dispose method to be called automatically, as clients can forget to call Dispose method? To Call the Dispose method in the Finalize method and in the Dispose

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd