1.建立类库:dpdll
2.项目>>dpdll属性,设置如下(程序集名字和空间名称,我用的是:DBJK):
注意:选择强名称密钥文件,可以随便起一个名字,但是”使用密码保护密钥文件“去掉。
3. 编写类文件,在类名称上面设置com可见属性[ComVisible(true)],需要引入:using System.Runtime.InteropServices;
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace DBJK
{
[ComVisible(true)]
public class Class1
{
public string text()
{
return "ok";
}
}
}
4. 生成DLL。
5. 注册DLL。
步骤:开始菜单==>Vistual Studio==>Vistual Studio Tools==>Vistual Studio 命令提示,
输入regasm d:\dpdll.dll /tlb: dpdll.tlb /codebase,将类型库导入到注册表。提示成功注册。
6.asp调用方法
<%
Set obj = CreateObject("DBJK.Class1")
Response.write(obj.text())
%>
输出结果:
关联文章:
32位DLL注册到64位系统下,需要把IIS中的“启用32位应用程序改为:true