.net创建一个ActiveX控件并使用的简单例子

在很多情况下,客户往往需要在客户端实现一些复杂的功能,有些可以通过AJAX来实现,有些则是现有客户端脚本不能完成的,此时则必须通过ActiveX控件来实现。

 

这里给出一个用.net编写简单的ActiveX并在网页中应用的例子:

 

 

///////////////////////////////////////////////////////////////////////////////////
// AxComp.cs
// Creates a simple ActiveX component.
//
// 1. Compile into a class library, or use: 
//    csc /t:library AxComp.cs
// 2. Register and generate the Typelib on the client's machine with:
//    regasm AxComp.dll /tlb:AxCompNet.dll /codebase
///////////////////////////////////////////////////////////////////////////////////

using System;
using System.Runtime.InteropServices;

namespace AxComponent 
{
 
public interface IAxTest
 {
  
string CallIt();
 }

 [ClassInterface(ClassInterfaceType.AutoDual)]
 
public class AxComp : IAxTest
 {
  
public string CallIt()
  {
   
return "This is a test.";
  }
 }
}

 

 

Code
posted @ 2008-08-04 10:23  LanceZhang  阅读(710)  评论(2)    收藏  举报