适用于32位和64位的Ptrsafe

问题描述

好..完全是新手,可能太老了,甚至无法理解其中的一些内容!我需要遵循才能与32bit和64bit兼容,我知道我需要使用PtrSafe并长时间更改为长ptr,但不知道我在做什么...任何帮助。

Option Explicit

Public Declare Function TzSpecificLocalTimetoSystemTime _
               Lib "Kernel32.dll" (ByRef lpTimeZone As TIME_ZONE_@R_750_4045@ION,_
                                   ByRef lpLocalTime As SYstemTIME,_
                                   ByRef lpUniversalTime As SYstemTIME) _
                                   As Long

Public Type TIME_ZONE_@R_750_4045@ION
    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_@R_750_4045@ION


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 lpUniversalTime As SYSTEMTIME) _
                                   As Long
#End If