I have created a very simple user control ActiveX with a simple button that show up a MessageBox.
namespace AxCPW
{
public partial class Test: UserControl, ITest
{
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello World");
}
}
}
Next I have created a web page inside my asp.net project and i have embedded my usercontrol in it.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<object id="myControl" name="myControl" classid="AxCPW.dll#AxCPW.Test" width="100" height="100">
</object>
</body>
</html>
The problem is i see a broken image instead my UserControl, i have already added my localhost web server Trusted Sites on IE9 but doesn’t works.
I know ActiveX is an obsolete solution, but i need to use a third part sdk dll (to communicate with a device by USB) and i think the only available solution is this
ActiveX is a COM technology (essentially it’s “COM-in-a-webpage”), and does not understand .NET technology.
To use an ActiveX control that has been developed in C#, you need to expose the interface through COM. Also, you will need to register the DLL using
RegAsm, rather thangacutilas you need the COM registration information written to the registry, rather than the assembly added to the GAC. Finally, theclassidattribute has to be the COM GUID, not the “friendly name”.If you need to deploy the ActiveX control automatically, and for sample HTML using the GUID, please check out my answer to Deploy C# ActiveX in a CAB for Internet Explorer use.