Creating ActiveX control in C# and calling it in the web page using Javascript

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>

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.