我已经更新了函数声明,以适应64位和32位Windows (VBA6 & VBA7)。我想保留这两个声明,因为我们的一些客户仍然使用Excel 2007。
问题是,在打开应用程序时,VBA6声明(在Else语句之后)有时(虽然并不总是)在Excel2016中抛出编译器错误(在Office365上测试,64位),尽管它永远不会被读取。
(编译错误:此项目中的代码必须更新,以便在64位系统上使用.)请检查和更新声明语句,并使用PtrSafe属性标记它们。)
有什么办法可以避免这种情况吗?
#If VBA7 Then
Private Declare PtrSafe Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare PtrSafe Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal
dwProcessId As Long) As Long
#Else
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
#End If发布于 2017-10-01 10:07:55
您对PtrSafe函数WaitForSingleObject的声明是错误的。这是科雷特的版本。
Declare PtrSafe Function WaitForSingleObject Lib "kernel32" _
Alias "WaitForSingleObject" ( _
ByVal hHandle As LongPtr, _
ByVal dwMilliseconds As Long _
) As Longhttps://stackoverflow.com/questions/46510642
复制相似问题