炬哥技术博客

ASP编译封装成DLL

炬哥 2023年06月26日 ASP 1747 0

具体步骤如下:

1、新建DLL

打开VB6-->文件-->新建工程-->选择ActiveX DLL-->打开

image.png


2、将默认工程、类重命名

工程重命名:工程-->工程1 属性(此名称对应窗体内工程项目名称)-->在打开对话框中将工程名称重命名为Tests(当DLL组件在系统中注册后,在asp中默认的调用方法是工程名.类名)-->确定

类重命名在属性窗口中将名称重命名为demo

image.png


3、增加到引用asp

点击工程引用,然后选择其中的

Microsoft Active Server Pages Object Library (ASP对象)

c:\windows\system32\inetsrv\asp.dll

c:\windows\syswow64\inetsrv\asp.dll

Microsoft VBscript Regular Expressions 5.5(RegExp对象)

c:\windows\system32\vbscript.dll

c:\windows\syswow64\vbscript.dll

image.png


4、编写代码

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 hello()
    Response.Write "ASP编译封装成DLL(https://blog.wetorch.net)"
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

5、保存工程文件

6、编译生成dll

如果没有错误提示的话说明编译成功,如果遇到访问注册表错误,是vb6没有管理员权限运行,右键使用管理员权限运行vb6就可以了。

7、注册dll

在Tests.dll组件所在目录创建 注册.bat 批处理文件,输入:

iisreset /stop
regsvr32 /s Tests.dll
iisreset /start

卸载.bat 批处理文件,输入:

iisreset /stop
regsvr32 /u /s Tests.dll
iisreset /start

双击运行注册.bat,成功注册会提示:Tests.dll 中的 Dll Register Server 成功。

8、asp中调用dll

新建demo.asp文件,输入代码:

<%
Dim Test
Set Test=Server.createObject("Tests.demo")
Test.hello()
%>

如果是64位系统,需要开启应用池32位应用程序:

image.png


访问demo.asp结果会输出:

ASP编译封装成DLL(https://blog.wetorch.net)


打赏 支付宝打赏 微信打赏

声明:本文由发布,如需转载请注明出处。

发布评论

分享到:

炬哥技术博客

欢迎炬哥微信号:4508175 (左侧二维码扫一扫)

利用Swoole提升PHP的并发能力
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,您可以吐槽或者留言。