COM class exposure

When this optional feature is enabled, the Visual Basic Upgrade Companion will generate attributes for the COM-exposed classes and their members, in order to keep the resulting assemblies exposed through a COM interface. This enables the resulting components to be called from other non-managed components via COM.

This feature is not available in the Upgrade Wizard, which means this backwards-compatibility feature must be manually implemented if needed.

In the example below, the original VB6 source code was contained in an ActiveX dll.

Original VB6 code:

Public Sub method1()
    MsgBox “Hello world”
End Sub

The Visual Basic Upgrade Companion generated source code will include some attributes to expose the resulting assemblies through a COM interface.

VB.NET code generated by the Visual Basic Upgrade Companion:

Option Strict Off
Option Explicit On
Imports System
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Generated attributes for COM visibility<ComVisible(True)>

Public Class Class1
    Public Sub method1()
        MessageBox.Show("hello world", Application.ProductName)    
    End Sub    
End Class

C# code generated by the Visual Basic Upgrade Companion:

using System; 
using System.Runtime.InteropServices; 
using System.Windows.Forms; 
using VB6 = Microsoft.VisualBasic.Compatibility.VB6.Support; 

Generated attributes for COM visibility Generated attributes for COM visibility[ComVisible(true)] [ProgId("Project1.Class1")] [ClassInterface(ClassInterfaceType.AutoDual)]
class Class1{
void method1(){ MessageBox.Show("hello world", Application.ProductName); }} }