看你知道不知道之-限制软件在规定的本地设置中运行

今天在处理一段程序的时候发现了一些异常情况,就是如果控制面板中的设置采用的是简体中文,程序运行正常,但是如果采用了英文或者其它国家的设置系统就报错误。

一般发生这种错误主要是因为程序与控制面板中的本地设置关系太紧,例如日期格式、本地的金融符号等,但是我的程序是采用RC6的算法进行一些字符串的加密,如果加解密的两端,本地设置不一样,解出来的内容就不一致。

呵呵,我的解决办法是限制用户必须是在简体中文的环境中使用,反正都是中国人使用,这样我就偷懒了,采用的如下代码。

' 读取本地的语言码
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

' 获得本地语言码
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

' 转换字符串
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

' 应用如下
     If  GetLocalLanguageCode  <>   " 0804 "   Then
        
MsgBox   " 本地控制面板设置错误,必须将控制面板设置为中文简体. " , vbCritical,  " 提示 "
        
End
    
End   If

这样就限制用户在规定的本地设置中进行操作,这个并不是很好的办法,但是够用就行了。

你可能感兴趣的:(算法,金融)