Sleep Lib “kernel32” gives 64-bit systems error

2020-08-13 02:31发布

问题:

I'm trying to close access (Application.Quit) after running all functions.

VBA close access after all functions finished has been a reference for me.

but when I Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long), It's giving me the following error:

The code in this project must be updated for use on 64 bit systems.

Is there any replacement of this code to do run all functions before completely closing access?

回答1:

The dwMilliseconds parameter is a DWORD, so it will technically be 32bit on a 32bit machine and 64bit on a 64bit machine. Because of this, it requires PtrSafe notation (although technically dwMilliseconds will marshal correctly because it's ByVal... and who wants to wait that long anyway) Change the declaration to this:

#If VBA7 Then
    Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If


回答2:

change your api declaration to this :

#If VBA7 And Win64 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If

For 64bit APIs read this: http://www.jkp-ads.com/articles/apideclarations.asp



标签: ms-access vba