Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 418721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:42:24+00:00 2026-05-12T18:42:24+00:00

I have a VB6 application implemented as an ActiveX exe. I also have a

  • 0

I have a VB6 application implemented as an ActiveX exe.
I also have a C# application that interacts with the VB6 app via COM.

This all works fine except in one scenario.

If the VB6 app is kicked off from the C# app, everything is fine. If, however, the VB6 app is already running stand-alone, then although the COM interface still works, the C# event handlers never fire.

A (very simplified) extract of the code follows, names & GUIDs changed to protect the innocent.

VB6 app: myVB6App.cls (GlobalSingleUse)

Event myEvent()

public function RaiseMyEvent()
    RaiseEvent myEvent
end function

(partial) IDL generated from the built VB6 exe:

...
[
  uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx),
  version(1.10),
  appobject
]
coclass myApp {
    [default] interface _myApp;
    [default, source] dispinterface __myApp;
};
...
[
  uuid(yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy),
  version(1.10),
  hidden,
  nonextensible
]
dispinterface __myApp {
    properties:
    methods:
        ...
        [id(0x00000005)]
        void myEvent();
        ...
};
...

C# app:

public class myAppInterface : IDisposable, ImyAppEvents
{
    public delegate void myEventDelegate();
    public event myEventDelegate myEventHandler;
    private object _myApp = null;
    private IConnectionPoint _connectionPoint;
    private int _sinkCookie;

    public myAppInterface()
    {
        _myApp = Activator.CreateInstance(Type.GetTypeFromProgID("myVB6ProjectName.myApp"));
        Guid g = new Guid("yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy");
        connectionPointContainer.FindConnectionPoint(ref g, out _connectionPoint);
        _connectionPoint.Advise(this, out _sinkCookie);
    }
    public void myEvent()
    {
        if (myEventHandler != null)
        {
            myEventHandler();
        }
    }
}

[ComImport, Guid("yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"), TypeLibType((short)4240)]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface ImyAppEvents
{
    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(5)]
        void myEvent();
}

public class myC#App
{
    private static myAppInterface _vb6App;
    public static myAppInterface VB6Application
    {
        get
        {
            if (_vb6App == null)
            {
                _vb6App = new myAppInterface();
                _vb6App.myEventHandler += new myAppInterface.myEventDelegate(DoSomething);
            }
            return _vb6App;
        }
    }
    static void DoSomething()
    {
        //code to actually handle the event
    }
}

As I say, if at the point that Activator.CreateInstance runs, the VB6 exe is not currently running, everything work as expected and the code in DoSomething() is executed when myEvent is fired in the VB6 app.

If the VB6 app is running stand-alone beforehand, the C# app can still control it via COM (methods not shown above for clarity) but the DoSomething() code never runs in response to myEvent.

Any ideas where I’m going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:42:24+00:00Added an answer on May 12, 2026 at 6:42 pm

    I would think that the problem lies in setting the sink for the event. At a quick guess I would say that you are creating a new instance of the VB component and assigning a new sink to the events generated by that instance rather than to the component already running.

    The VB6 documentation states:

    Setting the Instancing property of a class to GlobalMultiUse or
    GlobalSingleUse allows client programs to use the properties and
    methods of the class as if they were global functions, but within the
    project where you defined the GlobalMultiUse class module, objects
    created from the class are not global.

    The implication is that when you try to connect to a running instance, you’re actually getting a new copy of the VB6 class, with it’s own events, and NOT the already running class. Hence not receiving the events.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 199k
  • Answers 199k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Some canonized design patterns -- Adapter, Factory, Command, Visitor, etc… May 12, 2026 at 7:44 pm
  • Editorial Team
    Editorial Team added an answer I think execute_sql built in stored procedure can work around… May 12, 2026 at 7:44 pm
  • Editorial Team
    Editorial Team added an answer You won't be able to render HTML tags but you… May 12, 2026 at 7:44 pm

Related Questions

So here I am, first time windows developer (done java swing, iphone, flash/flex) and
I have a legacy VB6 ActiveX control used in IE to provide control of
I have a legacy COM-component with an interface declaring a property like this (IDL
I have a VB6 Application which creates an instance of the internet explorer and
I've got an old, legacy VB6 application that uses the DHTML editing control as

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.