微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用VB将ASP代码封装到DLL文件完整实例

使用VB将ASP代码封装到DLL文件完整实例

http://blog.csdn.net/cncco/archive/2007/10/20/1834865.aspx

用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

=================
以上代码在VB6,Win2003下测试通过.

说明:

声明部分:我们在调用自己的aplaction时,先要声明

OnStartPage部分:当ASP执行时就是在服务器上创建这些alacation

OnEndPage部分:当ASP执行完毕时消毁对象!

附:关闭和重启IIS来实现释放IIS调用的DLL文件,以修改它,否则提示"权限被拒绝!"

BAT文件:

@REM 重新启动IISADMIN服务,以便COM注册 @REM 停止IISADMIN服务 net stop iisadmin /y @REM 启动IISADMIN服务 net start iisadmin @REM 启动WWW服务 net start w3svc @REM 启动FTP服务 net start msftpsvc @REM net start smtpsvc @REM net start nntpsvc @REM pause...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐