Creating ActiveX control in C# and calling it in the web page using Javascript
Create a class file in visual studio express and name it as AxComp.cs and insert the following code in the class file.
// AxComp.cs
using System;
using System.Runtime.InteropServices;
namespace AXComponent
{
public interface AXTest
{
string callMe();
}
[ClassInterface(ClassInterfaceType.AutoDual)]
public class AxComp :AXTest
{
public string callMe()
{
return “My first activex control”;
}
}
}
Compile the class file using:
csc /t:library AxComp.cs
Register and generate Typelib with:
regasm AxComp.dll /tlb:AxCompNet.dll /codebase
Try the control in your web page(test.htm)
<html>
<head>
<script language=”javascript”>
var obNewAXComponent = new ActiveXObject(AXComponent.AXComp);
alert(obNewAXComponent.callMe());
</script>
</head>
<body>
<h1>Awful!</h1>
</body>
</html>
