在繁体操作系统中,需要将用户动态输入的BIG5码汉字,及时转换为GB2312码。在网上查到的资源如下:
'---------------------------------------------------
'GBK 码繁简转换
'阿勇 [email protected]
'--------------------API声明部分--------------------
Private Declare Function LCMapString Lib "kernel32" Alias "LCMapStringA" (ByVal Locale As Long, ByVal dwMapFlags As Long, ByVal lpSrcStr As String, ByVal cchSrc As Long, ByVal lpDestStr As String, ByVal cchDest As Long) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As LongPrivate Function GB2BIG(ByVal sStr As String) As String
'Gb2312 编码转换到 Big5 码,需要通过 GBK 编码过渡    Dim STR As String, STR2 As String
    
    '通过 API 转换成 GBK 码
    STR = GB2GBK(sStr)
    
    '从 GBK 编码转成 Big5
    STR2 = StrConv(STR, vbFromUnicode, &H404)
    GB2BIG = StrConv(STR2, vbUnicode, &H804)
End FunctionPrivate Function BIG2GB(ByVal sStr As String) As String
'Big5 编码转换到 Gb2312 编码,需要通过 GBK 编码过渡    Dim STR As String, STR2 As String
    
    'Big5 编码转换成 GBK
    STR = StrConv(sStr, vbFromUnicode, &H804)
    STR2 = StrConv(STR, vbUnicode, &H404)
    
    '用 API 将 GBK 转成 GB2312
    BIG2GB = GBK2GB(STR2)
End FunctionPrivate Function GB2GBK(ByVal gbStr As String) As String
'Gb码简体转GBK繁体    Dim strlen As Long
    strlen = lstrlen(gbStr)
    GB2GBK = Space(strlen)
    LCMapString &H804, &H4000000, gbStr, strlen, GB2GBK, strlen
End FunctionPrivate Function GBK2GB(ByVal bigStr As String) As String
'GBK码繁体转GB简体    Dim strlen As Long
    strlen = lstrlen(bigStr)
    GBK2GB = Space(strlen)
    LCMapString &H804, &H2000000, bigStr, strlen, GBK2GB, strlen
End Function
这个在简体操作系统中能工作的很好,但在繁体系统的表现不一样。
请高手指教,应该如何改,或有什么别的好办法?