Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Handling VB 6 events in C#

Posted on 2006-11-22
2
Medium Priority
?
236 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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