我的公司有一个 Office 加载项,可以在 Office 2007 和 2010 上运行,没有问题。现在Microsoft有了新的 Office 2013,我们需要在 Office 2013(32 位和 64 位)中测试加载项。
大多数函数工作正常,但不知何故,有一个使用 MsgWaitForMultipleObjects() 的函数在 Office 2013 64 位版本中无法正常工作,它在 32 位 Office 2013 上工作正常。 下面是我的代码,它在一个函数内:
Dim lReturn As Integer
Do While True
'Wait on event
lReturn = MsgWaitForMultipleObjects(1, handle, 0, timeout, QS_ALLEVENTS)
Select Case lReturn
Case -1
'Call failed
Err.Raise(vbObjectError, "WaitWithEvents", "MsgWaitForMultipleObjects Failed")
Case STATUS_TIMEOUT
'Timed out
WaitWithEvents = STATUS_TIMEOUT
Exit Function
Case 1
'Event needs to be processed
Application.DoEvents()
Case Else
'Event has been signaled
WaitWithEvents = 0
Exit Function
End Select
Loop
大多数情况下,MsgWaitForMultipleObjects() 将返回 -1,Office 应用程序将崩溃/挂起。我是MsgWaitForMultipleObjects()的新手,并尝试在这里和那里更改代码,但仍然无法解决问题。
MsgWaitForMultipleObjects() 在 64 位版本的 Office 2013 中是否运行良好?或者需要专门为 64 位 Office 进行一些修改? 还是需要以不同的方式注册 DLL?外接程序项目设置为任何 CPU。
谢谢。
我找到了解决方案,问题出在MsgWaitForMultipleObjects()的声明中。以前我是这样声明的:
Private Declare Function MsgWaitForMultipleObjects Lib "user32" (ByVal nCount As Integer, ByRef pHandles As Integer, ByVal fWaitAll As Integer, ByVal dwMilliseconds As Integer, ByVal dwWakeMask As Integer) As Integer
解决方案是:
Private Declare Function MsgWaitForMultipleObjects Lib "user32" (ByVal nCount As Integer, ByRef pHandles As IntPtr, ByVal fWaitAll As Boolean, ByVal dwMilliseconds As UInteger, ByVal dwWakeMask As Integer) As Integer