Solved

Handling VB 6 events in C#

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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