gpt4 book ai didi

dll - 如何拦截 VB6 ActiveX DLL 中的 DLL 加载/卸载事件?

转载 作者:行者123 更新时间:2023-12-04 07:01:37 27 4
gpt4 key购买 nike

我继承了一个传统的经典 ASP 应用程序,它使用 VB6 ActiveX DLL 来执行业务逻辑。

我想跟踪加载和卸载 DLL 的点。有没有办法在 VB6 DLL 中拦截这些事件?

在相关说明中,Class_Terminate 事件是否应该在其包含的 DLL 卸载时始终运行?

最佳答案

使用 Sub Main 作为您的启动对象。

制作这样的模块

Option Explicit

Private TerminateDetect As Terminate

Public Sub Main()
Set TerminateDetect = New Terminate
MsgBox "Setup"
End Sub

然后你的终止类看起来像这样
Option Explicit

Private Sub Class_Terminate()
MsgBox "I terminated"
End Sub

我做的一个测试课是这个
Option Explicit

Public Description As String

Public Sub Test()
MsgBox "test"
End Sub

我做了一个没有像这样的引用的表格
Option Explicit
Private O As Object

Private Sub Command1_Click()
Set O = CreateObject("TestUnload.Dummy")
O.Test
End Sub

Private Sub Command2_Click()
Set O = Nothing
End Sub

当我单击 Command1 时,我收到两条消息,一条用于加载 DLL,另一条用于运行测试。然后当我点击Command2。

这个例子相当粗略,所以我希望你明白这一点。

总结
在您拥有的每个 ActiveX 中创建一个 TDLLManagement 类。将初始化代码放在 Class_Initialize 中,将终止代码放在 Class_Terminate 中。然后让 Sub Main 创建该类的实例并分配给私有(private)模块变量。请注意,如果您有任何 GlobalMultisuse 类并直接引用 ActiveX DLL,您需要进行简单的测试以查看 DLL 的加载位置。

关于dll - 如何拦截 VB6 ActiveX DLL 中的 DLL 加载/卸载事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1754457/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com