Today, when processing a program, we found some exceptions, that is, if the settings in the control panel use simplified Chinese, the program runs normally, however, if the system is set up in English or other countries, an error is reported.
Generally, this error occurs because the program has a tight relationship with the local settings in the control panel, such as the date format and local financial symbols, however, my program uses the rc6 algorithm to encrypt some strings. If the encryption and decryption ends are different from the local settings, the obtained content is inconsistent.
Haha, my solution is to restrict users to use it in simplified Chinese environments, but they are all used by Chinese people. In this way, I am lazy and use the following code.
'Read the local language code
Private const locale_user_default = & H400
Private const locale_ilanguage = & H1
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
'Obtain the local language code
Private function getlocallanguagecode () as string
Dim buffer as string * 100
Dim DL as long
# If Win32 then
DL = getlocaleinfo (locale_user_default, locale_ilanguage, buffer, 99)
Getlocallanguagecode = lpstrtovbstring (buffer)
# End if
End Function
'Conversion string
Private function lpstrtovbstring (byval s as string) as string
Dim nullpos as long
Nullpos = instr (S, CHR (0 ))
If nullpos> 0 then
Lpstrtovbstring = left $ (S $, nullpos-1)
Else
Lpstrtovbstring = ""
End if
End Function
'Application:
If getlocallanguagecode <> "0804" then
Msgbox "Local Control Panel setting error, must be set to Chinese Simplified.", vbcritical, "prompt"
End
End if
In this way, the user is limited to perform operations in the specified local settings. This is not a good method, but it is enough.