Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an ActiveX control in C#?

I am not able to create a functioning ActiveX control in C#; I have tried following tutorials to do so without success.

I create a sample Class Library project which includes this code:

namespace AACWCSurvey
{
    [ProgId("Prisoner.PrisonerControl")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class Class1
    {
        public Class1()
        {
            MessageBox.Show("FIRETRUCK!!!");
        }
    }
}

I then did the following steps:

  1. Properties => Application => Assembly Information => Make Assembly COM-visible
  2. Build => Register for COM interop TRUE (checked)
  3. Make Strong name for assembly (signing)
  4. Build the project
  5. regasm MyDll.dll /tlb /codebase

  6. Can't see Prisoner.PrisonerControl in tstcon32 =(

My OS is WinXP x86.


UPD: it works from VBScript:

Dim objJava
Set objJava = WScript.CreateObject("Prisoner.PrisonerControl")

but it is not visible in tstcon32.

like image 743
VextoR Avatar asked Oct 10 '11 12:10

VextoR


People also ask

How do I use ActiveX control in MFC application?

To create an MFC ActiveX Control using the MFC ActiveX Control Wizard. Follow the instructions in the help topic Creating an MFC Application but choose MFC ActiveX Control from the list of available templates. Define your application settings, control names, and control settings using the MFC ActiveX Control Wizard.

What is ActiveX control example?

ActiveX controls are small program building blocks that can be used to create distributed applications that work over the Internet through web browsers. Examples include customized applications for gathering data, viewing certain kinds of files, and displaying animation.


1 Answers

If you read the actual article using the Prisoner.PrisonerControl control a sub key named Control is created inside the key with your control GUID.

On my machine with the guid {9DEA5F06-E324-31A7-837B-D0F3BDE91423} creating the key

HKEY_CLASSES_ROOT\CLSID\{9DEA5F06-E324-31A7-837B-D0F3BDE91423}\Control

Make the control appears in tstcon32. And with or without it the ActiveX is usable for javascript

var x = new ActiveXControl("Prisoner.PrisonerControl");

Actually i had to fight windows on both the javascript execution and registry path to test it on my system because it's an x64 machine but that's another story.

like image 144
Julien Roncaglia Avatar answered Sep 19 '22 11:09

Julien Roncaglia