我已将API声明为:
Private Declare Function GetTimeZoneInformation Lib "kernel32" (ByRef a_timezoneinfo As t_TimeZoneInfo) As Integer
t_TimeZoneInfo
结构定义如下:
Private Structure t_TimeZoneInfo
Dim tz_Bias As Integer
<VBFixedArray(32)> Dim tz_StandardName() As Short
Dim tz_StandardDateArray As t_SysTimeAsArray
Dim tz_StandardBias As Integer
<VBFixedArray(32)> Dim tz_DaylightName() As Short
Dim tz_DayLightDateArray As t_SysTimeAsArray
Dim tz_DaylightBias As Integer
Public Sub Initialize()
ReDim tz_StandardName(32)
tz_StandardDateArray.Initialize()
ReDim tz_DaylightName(32)
tz_DayLightDateArray.Initialize()
End Sub
End Structure
结构t_SysTimeAsArray
是:
Private Structure t_SysTimeAsArray
<VBFixedArray(8)> Dim w_timeval() As Short ' Y M Dw D G Min S mS
Public Sub Initialize()
ReDim w_timeval(8)
End Sub
End Structure
然后我在其他函数中有以下代码:
Dim lfmtres As String = ""
Dim lneedunicode As Boolean
Dim lres As Integer
lfmtres = CStr(a_tzinfo.tz_Bias) & "," & CStr(a_tzinfo.tz_DaylightBias) & "," & mCopyShortArrayToChars(a_tzinfo.tz_StandardName, 32, lneedunicode) & "," & mCopyShortArrayToChars(a_tzinfo.tz_DaylightName, 32, lneedunicode) & "," & mCopyShortArrayToNumString(a_tzinfo.tz_StandardDateArray.w_timeval, 8) & "," & mCopyShortArrayToNumString(a_tzinfo.tz_DayLightDateArray.w_timeval, 8)
lres = GetTimeZoneInformation(ltzinfo)
它会在行System.ExecutionEngineException
处抛出lres = GetTimeZoneInformation(ltzinfo)
类型的异常。好吧,我知道这种类型的异常通常发生在公共语言运行库的执行引擎中存在内部错误但我相信在我的情况下我在lib API声明中做错了。 (因为我已经尝试重新安装VS,在其他笔记本电脑上运行项目,更改版本但没有解决问题)。任何帮助将不胜感激。