【发布时间】:2020-01-10 14:37:39
【问题描述】:
我在我的 VB 代码(在 Windows 10 64 位和 Excel 64 位下)中声明了SetTimer,如下所示:
#If Win64 Then ' 64-bit Windows
' ---------------
#If VBA7 Then ' 64-bit Excel:
' -------------
Public Declare PtrSafe Function SetTimer Lib "user32" (ByVal hwnd As LongPtr, _
ByVal nIDEvent As LongPtr, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As LongPtr) As LongPtr
Public settimer_result As LongPtr ' Result value of SetTimer.
Public Declare PtrSafe Function KillTimer Lib "user32" (ByVal hwnd As LongPtr, _
ByVal nIDEvent As LongPtr) As Long
Public killtimer_result As Long ' Result value of KillTimer.
...
Public Const timer_interval As Long = 1000
...
当我运行程序时它工作正常,但是一旦我设置一个断点进行调试,Excel 就会在以下语句处崩溃:
settimer_result = SetTimer(0&, 0&, timer_interval, AddressOf TimerProc)
我也尝试过使用LongLong 而不是LongPtr,但它仍然崩溃。
非常感谢您对此的任何帮助。
【问题讨论】:
-
Doesn't 0& 只是声明为文字
Long但由于您的LongPtr声明,它会立即在 64 位 Excel 上转换为LongLong?我会取消&符号,它们是为了确保将正确类型的数据(长而不是整数)传递给弱类型声明,但你的声明是强类型的,所以你不需要它们。虽然如果这是导致崩溃的原因,我会感到惊讶。 -
嗨 Greedo,感谢您的建议。我试过了,但它仍然崩溃。还有什么建议吗?最好的问候,每安德斯
标签: vba