Hallo,
ich habe die Windows API-Funktion GetNumberFormatEx() deklariert, kann sie aber nicht erfolgreich aufrufen.
Dort liefert charCount immer "1". Das ist zwar keine Fehlermeldung, aber immer ein leerer String. Und wenn ich an flags einen Wert übergebe, der ungleich 0 ist, dann erhalte ich immer die Fehlermeldung "ungültiges Flag":
Private Declare PtrSafe Function GetDateFormatEx& Lib "Kernel32" ( _
ByVal lpLocaleName As String, _
ByVal dwFlags As Long, _
ByRef lpDate As SystemTime, _
ByVal lpFormat As String, _
ByVal lpDateStr As String, _
ByVal cchDate As Long, _
ByVal lpCalendar As String _
)
Private Type SystemTime
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Function DateToSystemTime(ByVal srcDate As Date) As SystemTime
With DateToSystemTime
.wDay = Day(srcDate)
.wMonth = Month(srcDate)
.wYear = Year(srcDate)
.wHour = Hour(srcDate)
.wMinute = Minute(srcDate)
.wSecond = Second(srcDate)
.wDayOfWeek = Weekday(srcDate, vbSunday)
End With
End Function
Public Function FormatDateLocale$(srcDate As Date, lcid$, Optional flags& = 0, Optional customFormat$ = vbNullString)
Dim buffer$
Dim charCount&
Dim sTime As SystemTime
lcid = StrConv(lcid, vbUnicode)
customFormat = StrConv(customFormat, vbUnicode)
sTime = DateToSystemTime(srcDate)
charCount = GetDateFormatEx(lcid, flags, sTime, customFormat, vbNullString, 0, vbNullString)
If charCount = 0 Then Err.Raise 1024, "FormatDateLocale", "Cannot format date value. Error code: " & Err.LastDllError
charCount = charCount * 2
buffer = String(charCount, vbNullChar)
charCount = GetDateFormatEx(lcid, flags, sTime, customFormat, buffer, charCount, vbNullString)
If charCount > 0 Then FormatDateLocale = Left$(StrConv(buffer, vbFromUnicode), charCount - 1)
End Function
Was habe ich falsch gemacht?
Vielen Dank für eure Hilfe!
|