查看: 50  |  回复: 0
  vb6 AddressOf的用法
楼主
发表于 2025年5月24日 22:24

新建From1(窗体),新建Command1(按钮CommandButton),代码:

Private Sub Command1_Click()
    ' 使用AddressOf获取s_TimerProc过程的地址并传递给timeSetEvent
    timeSetEvent 1000, 0, AddressOf s_TimerProc, 0, 0
End Sub

新建Module1(模块),代码:

Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal delay&, ByVal resolution&, ByVal lpFunction&, ByVal dwUser&, ByVal fuEvent&) As Long
 
Public Sub s_TimerProc(ByVal uID&, ByVal uMsg&, ByVal dwUser&, ByVal dw1&, ByVal dw2&)
    ' 处理计时器事件
    MsgBox "定时器启动了!"
End Sub

AddressOf 不能直接用于窗体(Form)中的过程,除非这些过程被声明为 Public 或 Friend 并且在标准模块(.bas 文件)中。这是因为 VB6 的编译方式限制了它只能为模块级的过程生成稳定的地址。

您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com