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

本文介绍如何使用.NET平台创建一个简单的ActiveX组件,并演示了如何在网页中使用该组件。通过实例代码展示了从编译到注册的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在很多情况下,客户往往需要在客户端实现一些复杂的功能,有些可以通过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.";
  }
 }
}

 

 

ContractedBlock.gifExpandedBlockStart.gifCode
///////////////////////////////////////////////////////////////////////////////////
// Tester.htm
// Test the ActiveX component.
///////////////////////////////////////////////////////////////////////////////////

<html>
<head>
<script language=JavaScript>
var g_axComponent = new ActiveXObject('AxComponent.AxComp');
alert(g_axComponent.CallIt());
</script>
</head>
 
<body>
  
<h1>Tester.htm</h1>
 
</body>
</html>

转载于:https://www.cnblogs.com/blodfox777/archive/2008/08/04/1259792.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值