Solved

Handling VB 6 events in C#

Posted on 2006-11-22
2
228 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
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now