Option Explicit
Const LOCALE_SLANGUAGE As Long = &H2
Const LOCALE_SENGLANGUAGE As Long = &H1001
Private Declare Function GetThreadLocale Lib "kernel32" () As Long
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Private Declare Function GetLocaleInfo Lib "kernel32" _
Alias "GetLocaleInfoA" _
(ByVal Locale As Long, _
ByVal LCType As Long, _
ByVal lpLCData As String, _
ByVal cchData As Long) As Long
Public Function GetUserLocaleInfo(ByVal dwLocaleID As Long, ByVal dwLCType As Long) As String
Dim sReturn As String
Dim r As Long
'call the function passing the Locale type
'variable to retrieve the required size of
'the string buffer needed
r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))
'if successful..
If r Then
'pad the buffer with spaces
sReturn = Space$(r)
'and call again passing the buffer
r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))
'if successful (r > 0)
If r Then
'r holds the size of the string
'including the terminating null
GetUserLocaleInfo = Left$(sReturn, r - 1)
End If
End If
End Function
Private Sub Command1_Click()
Dim LCID As Long
LCID = GetSystemDefaultLCID()
'localized name of language
Text1.Text = GetUserLocaleInfo(LCID, LOCALE_SLANGUAGE)
'English name of language
Text2.Text = GetUserLocaleInfo(LCID, LOCALE_SENGLANGUAGE)
End Sub