如何使代码兼容 32 位和 64 位

How to make code compatible with 32bit and 64bit

我需要以下内容以兼容 32 位和 64 位。

我知道我需要使用 PtrSafe 并将 long 更改为 long ptr 但不知道我在做什么。

Option Explicit

Public Declare Function TzSpecificLocalTimeToSystemTime _
               Lib "Kernel32.dll" (ByRef lpTimeZone As TIME_ZONE_INFORMATION, _
                                   ByRef lpLocalTime As SYSTEMTIME, _
                                   ByRef lpUniversalTime As SYSTEMTIME) _
                                   As Long

Public Type TIME_ZONE_INFORMATION
    Bias As Long
    StandardName(31) As Integer
    StandardDate As SYSTEMTIME
    StandardBias As Long
    DaylightName(31) As Integer
    DaylightDate As SYSTEMTIME
    DaylightBias As Long
End Type

Private mudtTZI As TIME_ZONE_INFORMATION


Public Function LocalTimeToUTC(utcTime As Date) As Date
    Dim localTime As Date
    Dim dteFileTime As FILETIME
    Dim dteLocalSystemTime As SYSTEMTIME
    Dim dteSystemTime As SYSTEMTIME

End Function

为 x86 或 x64 机器动态创建特定声明。有关上下文,请参阅 here。像这样:

#If VBA7 Then
Private Declare PtrSafe Function TzSpecificLocalTimeToSystemTime _
               Lib "Kernel32.dll" (ByRef lpTimeZone As TIME_ZONE_INFORMATION, _
                                   ByRef lpLocalTime As SYSTEMTIME, _
                                   ByRef lpUniversalTime As SYSTEMTIME) _
                                   As Long
#Else
Public Declare Function TzSpecificLocalTimeToSystemTime _
               Lib "Kernel32.dll" (ByRef lpTimeZone As TIME_ZONE_INFORMATION, _
                                   ByRef lpLocalTime As SYSTEMTIME, _
                                   ByRef lpUniversalTime As SYSTEMTIME) _
                                   As Long
#End If