gpt4 book ai didi

VBA AddressOf Crash Office 应用程序

转载 作者:行者123 更新时间:2023-12-01 16:33:07 24 4
gpt4 key购买 nike

我想运行一个简单的代码段,但每次 Access 和 Excel 都会崩溃。

我正在运行 CallbackTest2,你能帮帮我吗?谢谢分配。

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long

Sub CallbackTest2()
CallWindowProc AddressOf CallbackMsg, 0, 0, 0, 0
End Sub

Public Function CallbackMsg _
(msg As String, _
ByVal nUnused1 As Long, _
ByVal nUnused2 As Long, _
ByVal nUnused3 As Long)

MsgBox "CallBack Work :)" & msg
End Function

最佳答案

找到了解决方案。

我改变的事情:

  • CallbackMsg 从函数到子
  • 用数据填充的字符串参数 VarPtr("Hallo Welt")

  • 运行版本:
    Private Declare Function CallWindowProc _
    Lib "user32.dll" Alias "CallWindowProcA" ( _
    ByVal lpPrevWndFunc As Long, _
    ByVal hwnd As Long, _
    ByVal msg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    private Sub CallbackTest2()
    CallWindowProc AddressOf CallbackMsg, VarPtr("Hallo Welt"), 0, 0, 0
    End Sub

    Private Sub CallbackMsg( _
    msg As String, _
    ByVal nUnused1 As Long, _
    ByVal nUnused2 As Long, _
    ByVal nUnused3 As Long)
    MsgBox msg
    End Sub

    关于VBA AddressOf Crash Office 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24997849/

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