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:
- Properties => Application => Assembly Information => Make Assembly COM-visible
- Build => Register for COM interop TRUE (checked)
- Make Strong name for assembly (signing)
- Build the project
regasm MyDll.dll /tlb /codebase
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.
You have created a COM server but not an ActiveX control, which is a far more intricate COM object, the kind that you can exercise with tstcon32.exe.
It must implement a bunch of interfaces, key ones are IOleObject and IOleWindow. The kind of interfaces that allows it to do the required negotiations with an ActiveX host and create a visible window. The Winforms Control class is your best bet to create one.
Here are the relevant steps as documented externally. This is summarized leaving out some exposition but not any necessary steps.
This example is also very similar to the article Using Managed Controls as ActiveX Controls by Garry Trinder, November 25, 2008 and I've included some notes from this article as well.
[Here Garry's article suggests, "First, create a managed usercontrol project – either a Windows Forms class library or control library project. Use the usercontrol designer to design your custom usercontrol the way you want it (using any standard controls you like)."]
Additional notes from Garry's blog:
He describes the registry keys in some detail:
His final note is a warning:
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 keyMake the control appears in
tstcon32
. And with or without it the ActiveX is usable for javascriptActually 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.