Solved

Handling VB 6 events in C#

Posted on 2006-11-22
2
235 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:louiserutherford
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
jonorossi earned 250 total points
ID: 17996676
Have you tried doing this so that the instance of Class1 does not fall out of scope. I'm not sure if this is the problem.

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

Author Comment

by:louiserutherford
ID: 17996807
Thank you, that worked.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question