'help: Call C# winforms dll from VB6 project?

I have a VB6 project(windows application) and I have to redevelop a module in the existing VB6 project in C#.net.

The module that I develop in C#.net should be a dll and should contain some windows forms. I was able to successfully call a c# console applicaiton dll from my vb6 project but I am facing issues when i try to call a C# class library with winforms from my VB6 project.

This is what I have done for my Proof Of Concept - This is a class file in my C#.net class library project.

namespace TestDll
{
    public interface IClass1
    {
        void DisplayMessage();
    }


    public class Class1:IClass1
    {              
        void IClass1.DisplayMessage()
        { 
            MessageBox.Show ("Displyaing message");
        }

    }
}

I have a form in the same nemspace and I plan to instantiate Class1 and use its object on the page_load event of the C# winform.

In my VB6 project I want to display the form I have in my C#.net dll. I am calling it by this code -

Private Declare Sub DislayMessage Lib "TestDll.dll" ()

Private Sub Command1_Click() //On button click event of the VB6 windows form
DislayMessage
End Sub

I get an error - "Can't find a DLL entry point in DisplayMessage in TestDll.dll"

I am not sure how to solve this error. I am even skeptical if this is the way a C#.net dll which contains some winforms should be called from a VB6.0 windows applicaiton.

Should I instantiate Class1 in my VB6 code? How do I resolve this error? Is my approach correct? Are there better ways to do this?

TIA.



Solution 1:[1]

The only way to do it is to expose your C# class as a COM object (also called a CCW - COM Callable Wrapper), and create an instance of that COM object in your VB6 code.

This should help you get started:

http://www.bing.com/search?q=C%23+CCW&go=&form=QBRE&qs=n

Solution 2:[2]

There some excellent help on msdn here:

https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/com-interop/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 StayOnTarget