What is the best way to determine the correct encoding for a given LCID at runtime in VB6?

I show Japanese characters in a VB6 application with the system language installed in Japan and the language for programs that do not support Unicode, like Japanese. Calling GetACP () correctly returns 932 for the Japanese language. When I insert Japanese strings into my controls, they appear as "ƒAƒtƒŠƒJÌÌ- ‰ ¤", not "ア フ リ カ の 女王". If I manually set Font.Charset to 128, then they will display correctly.

What is the best way to determine the correct encoding for a given LCID in VB6?

+3
source share
3 answers

, , .

Private Const LOCALE_SYSTEM_DEFAULT As Long = &H800
Private Const LOCALE_IDEFAULTANSICODEPAGE As Long = &H1004
Private Const TCI_SRCCODEPAGE = 2

Private Type FONTSIGNATURE
    fsUsb(4) As Long
    fsCsb(2) As Long
End Type

Private Type CHARSETINFO
    ciCharset As Long
    ciACP As Long
    fs As FONTSIGNATURE
End Type

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

Private Declare Function TranslateCharsetInfo Lib "GDI32" ( _
    lpSrc As Long, _
    lpcs As CHARSETINFO, _
    ByVal dwFlags As Long _
) As Long

Public Function GetCharset() As Long
On Error GoTo ErrorHandler

    Dim outlen As Long
    Dim lCodepage As Long
    Dim outBuffer As String
    Dim cs As CHARSETINFO

    outBuffer = String$(10, vbNullChar)
    outlen = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, outBuffer, Len(outBuffer))

    If outlen > 0 Then
        lCodepage = val(Left$(outBuffer, outlen - 1))

        If TranslateCharsetInfo(ByVal lCodepage, cs, TCI_SRCCODEPAGE) Then
            GetCharset = cs.ciCharset
        End If
    End If

    Exit Function

ErrorHandler:
    GetCharset = 0
End Function
+2

The second best way is to use a database of fonts, font.charsets and heuristics, for example, here:

http://www.example-code.com/vb/vb6-display-unicode.asp

(The best way is to get out of the sinking ship, which is VB6)

+1
source

All Articles