在需要调用DLL信息的ASP页面顶部加上以下两句就OK啦,这样方便一些朋友使用的是虚拟主机,也没有注册组件的权限,小技巧,刚发现,学习学习!
程序代码
<% @ language="vbscript" %>Option Explicit Private Context As ScriptingContext Private Application As Application Private Response As Response Private Request As Request Private Session As Session Private Server As Server Public Sub OnStartPage(PassedscriptContext As ScriptingContext) Set Context = PassedscriptContext Set Application = Context.Application Set Request = Context.Request Set Response = Context.Response Set Server = Context.Server Set Session = Context.Session End Sub Public Sub showinfo() Response.Write "asp编译DLL,不需要服务器上注册组件!" End Sub ’释放内部对象 Public Sub OnEndPage() Set Application = Nothing Set Request = Nothing Set Response = Nothing Set Server = Nothing Set Session = Nothing Set Context = Nothing End Sub
在一般情况下,如我的dll放在了 d:\myweb\test.dll
那么需要服务器注册:regsvr32 d:\myweb\test.dll程序代码
<% Dim newtest Set newtest=Server.CreateObject("IT.hxw.red类模块名称") newtest.showinfo() %>在不注册组件的情况下,我们这样来使用:
<% @ language="vbscript" %> <!--METADATA TYPE="typelib" FILE="d:\myweb\test.dll"--> <% Dim newtest Set newtest=Server.CreateObject("类模块名称") newtest.showinfo() %>
就可以达到你所预想的效果!为了保护你的程序代码安全,编译DLL是个不错的选择!
不过以上方法,在本机测试通过,因为在编译DLL文件生成时,就已自动注册了DLL文件。把文件移到服务器上或其它电脑上测试,均不能正常运行~看来asp想使用dll封装技术,还是得注册组件,移动性低还是.net有前途呀!~