Passing Data from C# to VB6 Active X control (and vice versa)

Posted on 2008-11-17
Last Modified: 2013-12-26
I have an active X control written in VB6.  I am creating a C# project and need to pass data back and forth to the active x control.    Cant I just add the VB6 control to C# project reference and then be able to see public methods and send data over?   Is this possible?  What packages are needed to do this? COM.Interop?

Please help as soon as possible.


Question by:JohnnyKnoxville
    LVL 12

    Accepted Solution

    So your wanting a C# app to consume the VB6 ActiveX?  Yes com interop would be needed, is this a UI control? you will need to add it as a resource in that case.

    Author Comment

    The Active X control  must be registered with a 3rd party app.  This creates somewhat of a built in panel in the 3rd party app.  When the 3rd party app loads, it loads my active X control.  Now...if I have a .NET project and need to grab the handle of this active x is this accomplished?

    If I simply use..

    MyActiveXControl myCtrl = new MyActiveXControl();

    This will give me a new instance.  What I need is the existing handle to the instance when it loaded in the 3rd party app.  I need to be able to populate data into the VB6 controls (text box , combobox, etc)

    I tried to create a handle to the user control using CopyMemory  and expose it in a public class.  

    Now I try this in C#...

    MyActiveXControl.clsEventManagement myCtrl = new MyActiveXControl.clsEventManagement();
    myCtrl.PassDataToTextBox("Some String");

    This throws an error:

    Retrieving the COM class Factory for component with CLSID -{21301F0D-E249-4906-9D85-87D9DE8559EF  Failed due to the following reason 80040154

    Im completely stuck.  Im beginning to think its not possible to pass data back and forth because I cant get the original handle.  Is there a way to get a list of active window handles and look for my active x control?  Then try to grab it that way?

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    734 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

    19 Experts available now in Live!

    Get 1:1 Help Now