The following code is converted from VB6 to VS2005.
The call to GetLocaleInfoLS returns always 0.
Please HELP !!!!
<StructLayout(LayoutKind.Sequential)> _
Private Structure LOCALESIGNATURE
<VBFixedArray(3)> Dim lsUsb() As Integer
<VBFixedArray(1)> Dim lsCsbDefault() As Integer
<VBFixedArray(1)> Dim lsCsbSupported() As Integer
Public Sub Initialize()
ReDim lsUsb(3)
ReDim lsCsbDefault(1)
ReDim lsCsbSupported(1)
End Sub
End Structure
<StructLayout(LayoutKind.Sequential)> _
Private Structure CHARSETINFO
Dim ciCharset As Integer
Dim ciACP As Integer
Dim Fs As FONTSIGNATURE
Public Sub Initialize()
Fs = New FONTSIGNATURE
Fs.Initialize()
End Sub
End Structure
Private Const LOCALE_FONTSIGNATURE As Integer = &H58 ' font signature
Private Const TCI_SRCFONTSIG As Short = 3
Private Class Api
Declare Auto Function GetLocaleInfoLS Lib "kernel32" Alias
"GetLocaleInfoA" ( _
ByVal Locale As Integer, _
ByVal LCType As Integer, _
ByRef lpLCData As LOCALESIGNATURE, _
ByVal cchData As Integer) As Integer
Declare Auto Function TranslateCharsetInfo Lib "GDI32" ( _
ByRef lpSrc As Integer, _
ByRef lpcs As CHARSETINFO, _
ByVal dwFlags As Integer) As Integer
End Class
Private Function GetUserCharset() As Short
Dim ls As New LOCALESIGNATURE() ' local signature struct.
ls.Initialize()
Dim ci As New CHARSETINFO() ' character set info struct.
ci.Initialize()
Dim RC As Integer
Dim lsl As Integer = Marshal.SizeOf(ls)
' get locale signature based on the USER's Default LCID.
'
' what is wrong with this call ?????
'
RC =
Api.GetLocaleInfoLS(System.Globalization.CultureIn fo.CurrentCulture.LCID, _
LOCALE_FONTSIGNATURE, ls, lsl)
If (RC > 0) Then ' if success
ls.lsCsbDefault(1) = 0 ' zero out bits
' translate charset info from locale fontsignature.
RC = Api.TranslateCharsetInfo(ls.lsCsbDefault(0), ci,
TCI_SRCFONTSIG)
If RC <> 0 Then GetUserCharset = ci.ciCharset ' return charset
End If
End Function