COM Interoperability in .NET Part 2

The unmanaged code

Once the assembly is registered and properly installed, the types defined within the assembly can be used from COM as though they were normal COM types. Now you can create a simple VB 6 Standard EXE project type and as I already said confirm whether you set a reference to the new generated type Library. Place this code in the code section and now you see the usage of our .NET type in Classic COM.

Private Sub Command1_Click()
    Dim a As New Calculator
    MsgBox a.Add(100, 100), vbInformation, "ADDITION (100,100)"
    MsgBox a.GetType, vbInformation, "INFORMATION-TYPE"
    MsgBox a.Hello("India"), vbInformation, "STRING"
    MsgBox a.Subtract(100, 1), vbInformation, "SUBTRACTION(100-1)"
    Dim i As Imuldiv'INTERFACE
    Set i = a
    MsgBox i.Multiply(100, 100), vbInformation, "MULTIPLICATION(100*100)"
    MsgBox i.Division(100, 100), vbInformation, "DIVISION(100/100)"
End Sub

Summary

A lot of companies have spent a great amount of money and time in COM components. With introduction of .NET people are worried about the future of COM. Microsoft has recognized this and provide means to use classic COM components in .NET code and vice versa.

You might also like...

Comments

About the author

G.Gnana Arun Ganesh

G.Gnana Arun Ganesh India

G.Gnana Arun Ganesh is the Administrator and the Founder of ARUN MICRO SYSTEMS (www.arunmicrosystems.netfirms.com). He has been programming in C++, Visual Basic, COM, Java and Microsoft Technolo...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Engineers are all basically high-functioning autistics who have no idea how normal people do stuff.” - Cory Doctorow