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

  • SEARCH
  • Home
  • 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 8085465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:07:32+00:00 2026-06-05T18:07:32+00:00

I try to make an ActiveX by C# with COM-visible. It is a Windows

  • 0

I try to make an ActiveX by C# with COM-visible. It is a Windows Form. I built it successfully as a dll ActiveX, then I wrote a VBScript code to call it. The from appeared but disappeared right after that. I don’t know why @@
Here is my code:

C# code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Reflection;

namespace ActiveXTestLibrary
{
    [ProgId("ActiveXTestLibrary.UserControl")]
    [ClassInterface(ClassInterfaceType.AutoDispatch)]
    [ComVisible(true)] 
    public partial class UserControl1 : Form
    {
        public UserControl1()
        {
            InitializeComponent();
        }


        [ComVisible(true)]
        public void Hello()
        {
            this.Show();
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            this.lblResult.Text = "I am a .NET user control happily living \ninside an ActiveX container. Cheers.";
        }

        [ComRegisterFunction()]
        public static void RegisterClass(string key)
        {
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            RegistryKey ctrl = k.CreateSubKey("Control");
            ctrl.Close();

            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
            inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
            inprocServer32.Close();

            k.Close();
        }

        [ComUnregisterFunction()]
        public static void UnregisterClass(string key)
        {
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            if (k == null)
            {
                return;
            }
            k.DeleteSubKey("Control", false);

            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);

            inprocServer32.DeleteSubKey("CodeBase", false);

            inprocServer32.Close();
        }
    }
}

and VBScript:

Sub main
    set objTest = CreateObject("ActiveXTestLibrary.UserControl")
    objTest.Hello
end sub

call main
  • 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-06-05T18:07:35+00:00Added an answer on June 5, 2026 at 6:07 pm

    To show a form you need to start a message loop by calling Application.Run:

    [ComVisible(true)]
    public void Hello()
    {
        Applicaiton.Run(this);
    }
    

    The Show() function will show the form and immediately exit. Application.Run() will not exit until the form is closed.

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

Sidebar

Related Questions

I try to make a registration form. When user post the fields, i check
This is really strange behavior. When I try make a search using findItemsAdvanced to
i try to make my screen blinking like this: for (int i=0;i<10;i++) { targetView.setBackgroundColor(Color.BLUE);
I try to make this implementation of a multimap in C++, but I run
I try to make class where I can creat new object of Student. I've
I try to make div class and style together, but somehow style is not
I try to make a diagram with RGraph(JS). I have a user counter on
I try to make some maven plugin. I need to get path for artifact
I try to make an animation with an image in my view but it
I try to make Ext.Data.Store working... With a normal proxy it works great: var

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.