Use C # To create an ActiveX Control)

Source: Internet
Author: User

First, create the dll library, Code As follows:
Using system;
Using system. runtime. interopservices;
Namespace anamespace
{
// Define the COM Component Interface
Public interface asignatures
{
String fname ();
String sname ();
Int age {Get ;}
}
// Indicates that this class will be exposed as an interface of a COM Component
[Classinterface (classinterfacetype. autodual)]
Public class Aclass: asignatures
{
// Method for implementing the interface
Public String fname ()
{
Return "Imran ";
}
Public String sname ()
{
Return "nathani ";
}
Public int age
{
Get {return 24 ;}
}
}
}
Save the above Code as Aclass. CS, and then compile: CSC/T: Library Aclass. CS
You will get an Aclass. dll, and then register: regasm Aclass. dll/TLB/codebase
Finally, create an HTML test webpage with the following content:

<HTML>
<Head>
<Script language = "JavaScript">
<! -- Load the ActiveX Object -->
VaR x = new activexobject ("anamespace. Aclass ");

<! -- Access the method -->
Alert (X. fname ());
Alert (X. sname ());

<! -- Access the property -->
Alert (X. Age );
</SCRIPT>
</Head>
<Body>
</Body>
</Html>

Download the sample file:/files/margiex/testcom.rar
Source: http://dotnetslackers.com/articles/csharp/WritingAnActiveXControlInCSharp.aspx

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.