网络编程 
首页 > 网络编程 > 浏览文章

ASP 调用dll及封装dll实例

(编辑:jimmy 日期: 2025/2/27 浏览:3 次 )
打开VB6,新建ActiveX DLL
2、在工程引用中加入Microsoft Active Server Pages Object Library选择
3、填加代码如下:
复制代码 代码如下:
'Code Start
'声明部分
Private MyScriptingContext As ScriptingContext
Private MyApplication As Application
Private MyRequest As Request
Private MyResponse As Response
Private MyServer As Server
Private MySession As Session
'下面定义公用函数(在VB中访问ASP对象,即在VB中可以用MyApplication等同于ASP中的Application、MyRequest等同于ASP中的Request、 MyResponse等同于ASP中的Response、 MyServer等同于ASP中的Server、 MySession等同于ASP中的Session 使用)
Public Sub OnStartPage(PassedScriptingContext As ScriptingContext)
Set MyScriptingContext = PassedScriptingContext
Set MyApplication = MyScriptingContext.Application
Set MyRequest = MyScriptingContext.Request
Set MyResponse = MyScriptingContext.Response
Set MyServer = MyScriptingContext.Server
Set MySession = MyScriptingContext.Session
End Sub
Public Sub OnEndPage()
Set MyScriptingContext = Nothing
Set MyApplication = Nothing
Set MyRequest = Nothing
Set MyResponse = Nothing
Set MyServer = Nothing
Set MySession = Nothing
End Sub
'建立自定义函数SayHello
Public Sub SayHello()
MyResponse.Write ("Hello World")
End Sub
'Code End

4、将类名改为:HelloWorld 将工程名改为:TestVBCode
5、生成TestVBCode.DLL文件,并使用Windows运行注册组件命令Regsvr32 路径\TestVBCode.DLL注册后即可使用。(卸载组件命令为Regsvr32 /u 路径\TestVBCode.DLL)
6、建立Test.asp文件,代码如下
复制代码 代码如下:
<%
'VB自建函数调用格式
'Set 对象名=Server.CreateObject("工程名.类名")
'对象名.自建函数名
Set MyTestObj = Server.CreateObject("TestVBCode.HelloWorld")
MyTestObj.SayHello
%>

7、运行Test.asp文件结果显示如下:
Hello World
===========================================================
对于更复杂的运用,大家可以通过这个实例向外扩展就可以了.
如:
复制代码 代码如下:
Public Sub connstr2()
Set conn = MyServer.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & MyServer.MapPath("codata.mdb")
Set rs = conn.Execute("select * from news")
Do While Not rs.EOF
MyResponse.Write (rs("news_title") & "<br>")
rs.MoveNext
Loop
rs.Close
Set conn = Nothing
End Sub

这个是用数据库连接的代码封装,当然这里要添加ADO引用的.
上一篇:asp 实现的冒泡排序程序
下一篇:asp 获取url函数小结
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。