使用VB将ASP代码封装到DLL文件_ASP教程-查字典教程网
使用VB将ASP代码封装到DLL文件
使用VB将ASP代码封装到DLL文件
发布时间:2016-12-29 来源:查字典编辑
摘要:很久以前的文档,整理出来,回味一下使用VB封装ASP,建立SayHello测试程序1、打开VB6,新建ActiveXDLL2、在工程引用中加...

很久以前的文档,整理出来,回味一下

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

1、打开VB6,新建ActiveXDLL

2、在工程引用中加入MicrosoftActiveServerPagesObjectLibrary选择

3、填加代码如下:

'CodeStart

'声明部分

PrivateMyScriptingContextAsScriptingContext

PrivateMyApplicationAsApplication

PrivateMyRequestAsRequest

PrivateMyResponseAsResponse

PrivateMyServerAsServer

PrivateMySessionAsSession

'下面定义公用函数(在VB中访问ASP对象,即在VB中可以用MyApplication等同于ASP中的Application、MyRequest等同于ASP中的Request、MyResponse等同于ASP中的Response、MyServer等同于ASP中的Server、MySession等同于ASP中的Session使用)

PublicSubOnStartPage(PassedScriptingContextAsScriptingContext)

SetMyScriptingContext=PassedScriptingContext

SetMyApplication=MyScriptingContext.Application

SetMyRequest=MyScriptingContext.Request

SetMyResponse=MyScriptingContext.Response

SetMyServer=MyScriptingContext.Server

SetMySession=MyScriptingContext.Session

EndSub

PublicSubOnEndPage()

SetMyScriptingContext=Nothing

SetMyApplication=Nothing

SetMyRequest=Nothing

SetMyResponse=Nothing

SetMyServer=Nothing

SetMySession=Nothing

EndSub

'建立自定义函数SayHello

PublicSubSayHello()

MyResponse.Write("HelloWorld")

EndSub

'CodeEnd

4、将类名改为:HelloWorld将工程名改为:TestVBCode

5、生成TestVBCode.DLL文件,并使用Windows运行注册组件命令Regsvr32路径TestVBCode.DLL注册后即可使用。(卸载组件命令为Regsvr32/u路径TestVBCode.DLL)

6、建立Test.asp文件,代码如下

<%

'VB自建函数调用格式

'Set对象名=Server.CreateObject("工程名.类名")

'对象名.自建函数名

SetMyTestObj=Server.CreateObject("TestVBCode.HelloWorld")

MyTestObj.SayHello

%>

7、运行Test.asp文件结果显示如下:

HelloWorld

以上实例将开启你的VB编程世界之门

一起来吧,呵呵!

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新ASP教程学习
    热门ASP教程学习
    编程开发子分类