Outlook VBA - Run a code every half an hour with outlook 2010 64 bits

时光怂恿深爱的人放手 提交于 2019-12-22 13:55:20

问题


This question is done (and solved) before, see Outlook VBA - Run a code every half an hour I used the code fore several years on with no trouble on several computers running Vista (32 bit), Windows 7 and Windows 8.1 (all 64 bit). A new computer with a new office 2010 installation gives some problems.

The 64 bit version of outlook seems to react different as the 32 bit version. I get errors with these lines

Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerfunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

This can be corrected with PtrSafe like:

Declare Function PtrSafe SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerfunc As Long) As Long
Declare Function PtrSafe KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

An other error appear in the line:

TimerID = SetTimer(0, 0, nMinutes, AddressOf TriggerTimer)

The types seem to be different.


回答1:


PtrSafe is not correcting the code, its simply stating that the following declare can be called from 64 bit code.

The pointer returned by AddressOf is prototyped as ByVal lpTimerfunc As Long which is 32 bits; i.e. too small to accommodate a 64 bit address. The same is true of hwnd.

Use the LongPtr type to deal with this.



来源:https://stackoverflow.com/questions/23736851/outlook-vba-run-a-code-every-half-an-hour-with-outlook-2010-64-bits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!