Link to home
Start Free TrialLog in
Avatar of louiserutherford
louiserutherford

asked on

Handling VB 6 events in C#

I want a C# application to handle events fired by a VB6 application. I have created a test app to demonstrate what I am trying to achieve but the C# app never picks up the VB 6 events.

I have the following test VB 6 app:

Public Event FileClosed(ByVal strFilename As String)
Public Function getFileName()
    RaiseEvent FileClosed("C:\Test")
End Function

And the following C# test app that calls the above code:

    public partial class Form1 : Form
    {
        public delegate void __Class1_FileClosedEventHandler(string strFilename);

        public Form1()
        {
            InitializeComponent();
            Project1.Class1 cls = new Project1.Class1();
            cls.FileClosed +=new Project1.__Class1_FileClosedEventHandler(cls_FileClosed);
        }

        public void cls_FileClosed(string strFilename)
        {
            MessageBox.Show(strFilename);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Project1.Class1 obj = new Project1.Class1();
            obj.getFileName();
        }
    }

I can see that the VB app fires the event but it is not picked up by C#. Has anyone any ideas as to what I'm doing wrong?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of jonorossi
jonorossi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of louiserutherford
louiserutherford

ASKER

Thank you, that worked.