加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

运用VB将ASP代码封装到DLL文件

发布时间:2023-09-06 14:09:27 所属栏目:Asp教程 来源:
导读:很久以前的文档,整理出来,回味一下

使用VB封装ASP,建立SayHello测试程序

1、打开VB6,新建ActiveX DLL

2、在工程引用中加入Microsoft Active Server Pages Object Library选择

3、填加代码如下:
很久以前的文档,整理出来,回味一下
 
使用VB封装ASP,建立SayHello测试程序
 
1、打开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
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章