Add COM - Visible Attributes

    There are some cases when a company might want to convert some of its VB6 modules to .NET and keep using them in a COM environment.

    E.g.: convert the logic libraries and keep the front end in VB6. The “COM Visible” feature was implemented to assist in this scenarios.

    When this optional feature is enabled, the VBUC 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. A brief code sample:

    Original VB6 Code:

    The following method is declared in an ActiveX dll.

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

    Resulting VB.NET Code:

    Option Strict Off
    Option Explicit On
    Imports System
    Imports System.Runtime.InteropServices
    Imports System.Windows.Forms
    <ComVisible(True)> _
    <ProgId("Project1.Class1")> _
    <ClassInterface(ClassInterfaceType.AutoDual)> _
    Public Class Class1
        Public Sub method1()
            MessageBox.Show("hello world", Application.ProductName)
        
        End Sub    
    End Class

    Resulting C#.NET Code:

    using System; 
    using System.Runtime.InteropServices; 
    using System.Windows.Forms; 
    using VB6 = Microsoft.VisualBasic.Compatibility.VB6.Support; 
    
    namespace Project1{
    
    [ComVisible(true)][ProgId("Project1.Class1")][ClassInterface(ClassInterfaceType.AutoDual)]
    public class Class1{
    
    public void  method1(){
        MessageBox.Show("hello world", Application.ProductName);
    }}
    }

    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration