VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)

VB爱好者乐园(VBGood)

 找回密码
 立即注册
搜索
查看: 8411|回复: 19

[讨论] 4个简繁转换相关的程序[开源]还一个全用API转换Big2GB的问题

[复制链接]
 楼主| 发表于 2008-12-25 23:55:54 | 显示全部楼层 |阅读模式
压缩包中有4个简繁转换相关的程序

2个实现GBK编码(或者说是Unicode)的简体字繁体字转换(不是Big5与GB编码转换)(分别使用的字库,是从看到的转换软件中拿来模仿写的),示例 示例说明:  繁转简:中?->中国  简转繁:中国->中?

1个是VB的StrConv函数和 API函数 LCMapString 很好的实现了Big2GB 简繁转换。

最后1个是存在问题的程序,不用strConv函数,完全用API函数来实现,下面说明和贴图

问题是使用模仿下面的ASM版和VC版的 Big2GB的API实现代码。VB代码已经可以运行,一般的Big5可以正确转换成GB简体,但是运行测试发现“MsgBox "E郎?岿?"”,用VB版的转换就是不完整的“MsgBox "E档???”,而ASM版的则可以正确转换出结果“MsgBox "E档头错误"”

请大家帮忙看下代码,问题出在哪里。

之前已经有个贴子讨论这个用API来实现简繁转换的帖子  解决简繁转换
这个是把下面的VC版的Big2GB转换改成VB的,但是问题和上面的说明一样。

Public Function Big2GB(ByVal strSource As String) As String
   
    Dim strUnicode As String
    Dim strGBKT As String
    Dim strGBKS As String
   
    Dim lngRet As Long
    Dim lngLen As Long
   
    'Big5 -> Unicode
    '用MultiByteToWideChar来返回字符个数
    lngLen = MultiByteToWideChar(950, 0, strSource, -1, vbNullString, 0)         'MultiByteToWideChar 返回的是字符个数,乘 2 才是所需要分配的空间
'    lngLen = lngLen - 1        'MultiByteToWideChar 返回的个数多了1
   
'    lngLen = Len(strSource) '使用VB自带的函数Len返回字符个数
   
    strUnicode = String(lngLen * 2, 0)
    lngRet = MultiByteToWideChar(950, 0, strSource, -1, strUnicode, lngLen)
   
    'Unicode -> GB 繁体
    lngLen = WideCharToMultiByte(936, 0, strUnicode, -1, vbNullString, 0, vbNullString, 0)
   
    'lngLen = Len(strUnicode)
    strGBKT = String(lngLen, 0)
    lngLen = WideCharToMultiByte(936, 0, strUnicode, -1, strGBKT, lngLen, vbNullString, 0)
   
    'GB 繁体 -> GB 简体
    strGBKS = String(lngLen, 0)
    lngRet = LCMapString(&H804, &H2000000, strGBKT, -1, strGBKS, lngLen)
   
    Big2GB = strGBKS
   
End Function


______________________________________________________________________________

一块三毛钱的汇编  API实现Big2GB 简繁转换程序,效果很不错。

_Big2GB proc lpSource: DWORD, lpDest: DWORD
        LOCAL        dwLen
       
        pushad
       
        ;Big5 -> Unicode
        mov        esi, lpSource
        invoke        MultiByteToWideChar, 950, 0, esi, -1, NULL, 0
        mov        dwLen, eax
        shl        eax, 1        ;MultiByteToWideChar 返回的是字符个数,乘 2 才是所需要分配的空间
        inc        eax
        invoke        GlobalAlloc, GMEM_FIXED + GMEM_ZEROINIT, eax
        mov        edi, eax
        invoke        MultiByteToWideChar, 950, 0, esi, -1, edi, dwLen
       
        ;Unicode -> GB 繁体
        invoke        WideCharToMultiByte, 936, 0, edi, -1, NULL, 0, 0, 0
        mov        dwLen, eax
        inc        eax
        invoke        GlobalAlloc, GMEM_FIXED + GMEM_ZEROINIT, eax
        mov        esi, eax
        invoke        WideCharToMultiByte, 936, 0, edi, -1, esi, dwLen, 0, 0
        push        eax
        invoke        GlobalFree, edi
       
        ;GB 繁体 -> GB 简体
        pop        eax
        mov        dwLen, eax
        inc        eax
        invoke        GlobalAlloc, GMEM_FIXED + GMEM_ZEROINIT, eax
        mov        edi, eax
        invoke        LCMapString, 0804h, 2000000h, esi, -1, edi, dwLen
        invoke        GlobalFree, esi
       
        mov        eax, edi
        mov        esi, eax
        mov        edi, lpDest
        mov        ecx, dwLen
        rep movsb
        invoke        GlobalFree, eax
       
        popad
        ret
_Big2GB endp


_GB2Big proc lpSource: DWORD, lpDest: DWORD
        LOCAL        dwLen
       
        pushad
       
        ;GB 简体 -> GB 繁体
        mov        esi, lpSource
        invoke        MultiByteToWideChar, 936, 0, esi, -1, NULL, 0
        mov        dwLen, eax
        shl        eax, 1        ;MultiByteToWideChar 返回的是字符个数,乘 2 才是所需要分配的空间
        inc        eax
        invoke        GlobalAlloc, GMEM_FIXED + GMEM_ZEROINIT, eax
        mov        edi, eax
        mov        eax, dwLen
        shl        eax, 1
        invoke        LCMapString, 0804h, 4000000h, esi, -1, edi, eax
       
        ;GB 繁体 -> Unicode
        mov        eax, dwLen
        shl        eax, 1
        inc        eax
        invoke        GlobalAlloc, GMEM_FIXED + GMEM_ZEROINIT, eax
        mov        esi, eax
        invoke        MultiByteToWideChar, 936, 0, edi, -1, esi, dwLen
        invoke        GlobalFree, edi
       
        ;Unicode -> Big5
        invoke        WideCharToMultiByte, 950, 0, esi, -1, NULL, 0, 0, 0
        mov        dwLen, eax
        inc        eax
        invoke        GlobalAlloc, GMEM_FIXED + GMEM_ZEROINIT, eax
        mov        edi, eax
        invoke        WideCharToMultiByte, 950, 0, esi, -1, edi, dwLen, 0, 0
        invoke        GlobalFree, esi
       
        mov        eax, edi
        mov        esi, eax
        mov        edi, lpDest
        mov        ecx, dwLen
        rep movsb
        invoke        GlobalFree, eax
       
        popad
        ret
_GB2Big endp

______________________________________________________________________________

zzzsssccc  的 VC API实现Big2GB 简繁转换程序,与上面的ASM汇编实现的程序差不多。
http://blog.csdn.net/zzzsssccc/archive/2004/04/15/5388.aspx


    //---------------------------------------------------------------------------
    //函数输入Big5字符,返回Gb简体字符
    //---------------------------------------------------------------------------
    AnsiString __fastcall Big2Gb(AnsiString sBig)
    {
     char* pszBig5=NULL; //Big5编码的字符
     wchar_t* wszUnicode=NULL; //Unicode编码的字符
     char* pszGbt=NULL; //Gb编码的繁体字符
     char* pszGbs=NULL; //Gb编码的简体字符
     AnsiString sGb; //返回的字符串
     int iLen=0; //需要转换的字符数
   
     pszBig5=sBig.c_str(); //读入需要转换的字符参数
   
     //计算转换的字符数
     iLen=MultiByteToWideChar (950, 0, pszBig5, -1, NULL,0) ;
     //给wszUnicode分配内存
     wszUnicode=new wchar_t[iLen+1];
     //转换Big5码到Unicode码,使用了API函数MultiByteToWideChar
     MultiByteToWideChar (950, 0, pszBig5, -1, wszUnicode,iLen);
   
     //计算转换的字符数
     iLen=WideCharToMultiByte (936, 0, (PWSTR) wszUnicode, -1, NULL,0, NULL, NULL) ;
     //给pszGbt分配内存
     pszGbt=new char[iLen+1];
     //给pszGbs分配内存
     pszGbs=new char[iLen+1];
     //转换Unicode码到Gb码繁体,使用API函数WideCharToMultiByte
     WideCharToMultiByte (936, 0, (PWSTR) wszUnicode, -1, pszGbt,iLen, NULL, NULL) ;
   
     //转换Gb码繁体到Gb码简体,使用API函数LCMapString
     LCMapString(0x0804,LCMAP_SIMPLIFIED_CHINESE, pszGbt, -1, pszGbs, iLen);
   
     //返回Gb码简体字符
     sGb=pszGbs;
   
     //释放内存
     delete [] wszUnicode;
     delete [] pszGbt;
     delete [] pszGbs;
     
     return sGb;
    }


    //---------------------------------------------------------------------------
    //函数输入Gb字符,返回Big5字符
    //---------------------------------------------------------------------------
    AnsiString __fastcall Gb2Big(AnsiString sGb)
    {
     char* pszGbt=NULL; //Gb编码的繁体字符
     char* pszGbs=NULL; //Gb编码的简体字符
     wchar_t* wszUnicode=NULL; //Unicode编码的字符
     char* pszBig5=NULL; //Big5编码的字符
     AnsiString sBig5; //返回的字符串
     int iLen=0; //需要转换的字符数
   
     pszGbs=sGb.c_str(); //读入需要转换的字符参数
   
     //计算转换的字符数
     iLen=MultiByteToWideChar (936, 0, pszGbs, -1, NULL,0) ;
   
     //给pszGbt分配内存
     pszGbt=new char[iLen*2+1];
     //转换Gb码简体到Gb码繁体,使用API函数LCMapString
     LCMapString(0x0804,LCMAP_TRADITIONAL_CHINESE, pszGbs, -1, pszGbt, iLen*2);
   
     //给wszUnicode分配内存
     wszUnicode=new wchar_t[iLen+1];
     //转换Gb码到Unicode码,使用了API函数MultiByteToWideChar
     MultiByteToWideChar (936, 0, pszGbt, -1, wszUnicode,iLen);
   
     //计算转换的字符数
     iLen=WideCharToMultiByte (950, 0, (PWSTR) wszUnicode, -1, NULL,0, NULL, NULL) ;
     //给pszBig5分配内存
     pszBig5=new char[iLen+1];
     //转换Unicode码到Big5码,使用API函数WideCharToMultiByte
     WideCharToMultiByte (950, 0, (PWSTR) wszUnicode, -1, pszBig5,iLen, NULL, NULL) ;
   
     //返回Big5码字符
     sBig5=pszBig5;
   
     //释放内存
     delete [] wszUnicode;
     delete [] pszGbt;
     delete [] pszBig5;
   
     return sBig5;
    }

[ 本帖最后由 新林 于 2008-12-25 23:59 编辑 ]
简繁转换1.jpg
简繁转换2.jpg

ASM版 转换正确

ASM版 转换正确

VB版 转换发现问题

VB版 转换发现问题

简繁转换.rar

89.48 KB, 下载次数: 765

源码压缩包

评分

参与人数 1威望 +1 人气 +1 收起 理由
艾达 + 1 + 1 发布源码

查看全部评分

本帖被以下淘专辑推荐:

 楼主| 发表于 2008-12-26 00:00:21 | 显示全部楼层
怎么里面PE的P被换成笑脸表情了,应该要“: P”(没有中间的空格)才会转换的嘛。

[ 本帖最后由 新林 于 2008-12-26 00:01 编辑 ]
回复 支持 反对

使用道具 举报

发表于 2008-12-26 08:07:37 | 显示全部楼层

  1. '代码加 [cod e] [/cod e]吧
复制代码
回复 支持 反对

使用道具 举报

发表于 2008-12-26 09:14:10 | 显示全部楼层
你的繁简转换不顶!好像不行。
提示:
'=====================================================
'Support Unicode Format: ANSI,UTF-8,UTF-16LE,UTF-16BE
'=================================================

'## API ####################################################

Private Declare Function CreateFileW Lib "kernel32" (ByVal lpFileName As Long, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function lstrlenW Lib "kernel32" (ByVal psString As Any) As Long
Private Declare Function LCMapStringW Lib "kernel32" (ByVal Locale As Long, ByVal dwMapFlags As Long, ByVal lpSrcStr As Long, ByVal cchSrc As Long, ByVal lpDestStr As Long, ByVal cchDest As Long) As Long

Private Declare Function CreateFile Lib "KERNEL32.dll" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByRef lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function LCMapString Lib "KERNEL32.dll" 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.dll" Alias "lstrlenA" (ByVal lpString As String) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long

Private Const INVALID_HANDLE_VALUE = -1

Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000

Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2

Private Const CREATE_NEW = 1
Private Const CREATE_ALWAYS = 2
Private Const OPEN_EXISTING = 3
Private Const OPEN_ALWAYS = 4
Private Const TRUNCATE_EXISTING = 5

Private Const FILE_ATTRIBUTE_NORMAL = &H80

Private Const FILE_BEGIN = 0
Private Const FILE_CURRENT = 1
Private Const FILE_END = 2

'== Unicode ================================================

Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByRef lpWideCharStr As Any, ByVal cchWideChar As Long) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpWideCharStr As Any, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByRef lpDefaultChar As Any, ByVal lpUsedDefaultChar As Long) As Long

Private Const CP_UTF8 As Long = 65001
Private Const CP_UTF7 As Long = 65000

'###########################################################
'GB to BIG5
Private Const LCMAP_BYTEREV As Long = &H800
Private Const LCMAP_FULLWIDTH As Long = &H800000
Private Const LCMAP_HALFWIDTH As Long = &H400000
Private Const LCMAP_HIRAGANA As Long = &H100000
Private Const LCMAP_KATAKANA As Long = &H200000
Private Const LCMAP_LINGUISTIC_CASING As Long = &H1000000
Private Const LCMAP_LOWERCASE As Long = &H100
Private Const LCMAP_SIMPLIFIED_CHINESE As Long = &H2000000
Private Const LCMAP_SORTKEY As Long = &H400
Private Const LCMAP_TRADITIONAL_CHINESE As Long = &H4000000
Private Const LCMAP_UPPERCASE As Long = &H200

'Lang ID
Private Const LANG_CHINESE As Long = &H4

'SubLang ID
Private Const SUBLANG_CHINESE_TRADITIONAL As Long = &H1
Private Const SUBLANG_CHINESE_SIMPLIFIED As Long = &H2
Private Const SUBLANG_CHINESE_HONGKONG As Long = &H3
Private Const SUBLANG_CHINESE_SINGAPORE As Long = &H4
Private Const SUBLANG_CHINESE_MACAU As Long = &H5

'Sort
Private Const SORT_CHINESE_PRCP As Long = &H0
Private Const SORT_CHINESE_BIG5 As Long = &H0
Private Const SORT_CHINESE_UNICODE As Long = &H1
Private Const SORT_CHINESE_PRC As Long = &H2
Private Const SORT_CHINESE_BOPOMOFO As Long = &H3

'Generate LCID
Private Const LCID_CHINESE_SIMPLIFIED As Long = (LANG_CHINESE Or SUBLANG_CHINESE_SIMPLIFIED * &H400) And &HFFFF& Or SORT_CHINESE_PRCP * &H10000
Private Const LCID_CHINESE_TRADITIONAL As Long = (LANG_CHINESE Or SUBLANG_CHINESE_TRADITIONAL * &H400) And &HFFFF& Or SORT_CHINESE_BIG5 * &H10000

Private Const LCID_INSTALLED As Long = &H1
Private Const LCID_SUPPORTED As Long = &H2

'Unicode Format
Public Enum UnicodeEncodeFormat
    UEF_ANSI = &H1&    'ANSI+DBCS
    UEF_UTF7 = &H2&      'UTF7 '&H38 76 2F 2B
    UEF_UTF8 = &H4&      'UTF-8
    UEF_UTF16LE = &H8&  'UTF-16LE
    UEF_UTF16BE = &H10&  'UTF-16BE
    UEF_UTF32LE = &H20&   'UTF-32LE
    UEF_UTF32BE = &H40&   'UTF-32BE
   
    UEF_Auto = &H0& 'Auto Recognize Text File Format

    'Hide Project
    [_UEF_Min] = UEF_ANSI
    [_UEF_Max] = UEF_UTF32BE

End Enum

Public Enum LocaleInfoTypes
    LOCALE_ILANGUAGE = &H1             '  language id
    LOCALE_SLANGUAGE = &H2             '  localized name of language
    LOCALE_SENGLANGUAGE = &H1001       '  English name of language
    LOCALE_SABBREVLANGNAME = &H3       '  abbreviated language name
    LOCALE_SNATIVELANGNAME = &H4       '  native name of language
    LOCALE_ICOUNTRY = &H5              '  country code
    LOCALE_SCOUNTRY = &H6              '  localized name of country
    LOCALE_SENGCOUNTRY = &H1002        '  English name of country
    LOCALE_SABBREVCTRYNAME = &H7       '  abbreviated country name
    LOCALE_SNATIVECTRYNAME = &H8       '  native name of country
    LOCALE_IDEFAULTLANGUAGE = &H9      '  default language id
    LOCALE_IDEFAULTCOUNTRY = &HA       '  default country code
    LOCALE_IDEFAULTCODEPAGE = &HB      '  default code page
    LOCALE_SLIST = &HC                 '  list item separator
    LOCALE_IMEASURE = &HD              '  0 = metric, 1 = US
    LOCALE_SDECIMAL = &HE              '  decimal separator
    LOCALE_STHOUSAND = &HF             '  thousand separator
    LOCALE_SGROUPING = &H10            '  digit grouping
    LOCALE_IDIGITS = &H11              '  number of fractional digits
    LOCALE_ILZERO = &H12               '  leading zeros for decimal
    LOCALE_SNATIVEDIGITS = &H13        '  native ascii 0-9
    LOCALE_SCURRENCY = &H14            '  local monetary symbol
    LOCALE_SINTLSYMBOL = &H15          '  intl monetary symbol
    LOCALE_SMONDECIMALSEP = &H16       '  monetary decimal separator
    LOCALE_SMONTHOUSANDSEP = &H17      '  monetary thousand separator
    LOCALE_SMONGROUPING = &H18         '  monetary grouping
    LOCALE_ICURRDIGITS = &H19          '  # local monetary digits
    LOCALE_IINTLCURRDIGITS = &H1A      '  # intl monetary digits
    LOCALE_ICURRENCY = &H1B            '  positive currency mode
    LOCALE_INEGCURR = &H1C             '  negative currency mode
    LOCALE_SDATE = &H1D                '  date separator
    LOCALE_STIME = &H1E                '  time separator
    LOCALE_SSHORTDATE = &H1F           '  short date format string
    LOCALE_SLONGDATE = &H20            '  long date format string
    LOCALE_STIMEFORMAT = &H1003        '  time format string
    LOCALE_IDATE = &H21                '  short date format ordering
    LOCALE_ILDATE = &H22               '  long date format ordering
    LOCALE_ITIME = &H23                '  time format specifier
    LOCALE_ICENTURY = &H24             '  century format specifier
    LOCALE_ITLZERO = &H25              '  leading zeros in time field
    LOCALE_IDAYLZERO = &H26            '  leading zeros in day field
    LOCALE_IMONLZERO = &H27            '  leading zeros in month field
    LOCALE_S1159 = &H28                '  AM designator
    LOCALE_S2359 = &H29                '  PM designator
    LOCALE_SDAYNAME1 = &H2A            '  long name for Monday
    LOCALE_SDAYNAME2 = &H2B            '  long name for Tuesday
    LOCALE_SDAYNAME3 = &H2C            '  long name for Wednesday
    LOCALE_SDAYNAME4 = &H2D            '  long name for Thursday
    LOCALE_SDAYNAME5 = &H2E            '  long name for Friday
    LOCALE_SDAYNAME6 = &H2F            '  long name for Saturday
    LOCALE_SDAYNAME7 = &H30            '  long name for Sunday
    LOCALE_SABBREVDAYNAME1 = &H31      '  abbreviated name for Monday
    LOCALE_SABBREVDAYNAME2 = &H32      '  abbreviated name for Tuesday
    LOCALE_SABBREVDAYNAME3 = &H33      '  abbreviated name for Wednesday
    LOCALE_SABBREVDAYNAME4 = &H34      '  abbreviated name for Thursday
    LOCALE_SABBREVDAYNAME5 = &H35      '  abbreviated name for Friday
    LOCALE_SABBREVDAYNAME6 = &H36      '  abbreviated name for Saturday
    LOCALE_SABBREVDAYNAME7 = &H37      '  abbreviated name for Sunday
    LOCALE_SMONTHNAME1 = &H38          '  long name for January
    LOCALE_SMONTHNAME2 = &H39          '  long name for February
    LOCALE_SMONTHNAME3 = &H3A          '  long name for March
    LOCALE_SMONTHNAME4 = &H3B          '  long name for April
    LOCALE_SMONTHNAME5 = &H3C          '  long name for May
    LOCALE_SMONTHNAME6 = &H3D          '  long name for June
    LOCALE_SMONTHNAME7 = &H3E          '  long name for July
    LOCALE_SMONTHNAME8 = &H3F          '  long name for August
    LOCALE_SMONTHNAME9 = &H40          '  long name for September
    LOCALE_SMONTHNAME10 = &H41         '  long name for October
    LOCALE_SMONTHNAME11 = &H42         '  long name for November
    LOCALE_SMONTHNAME12 = &H43         '  long name for December
    LOCALE_SMONTHNAME13 = &H100E       '  long name for 13th month (if exists)
    LOCALE_SABBREVMONTHNAME1 = &H44    '  abbreviated name for January
    LOCALE_SABBREVMONTHNAME2 = &H45    '  abbreviated name for February
    LOCALE_SABBREVMONTHNAME3 = &H46    '  abbreviated name for March
    LOCALE_SABBREVMONTHNAME4 = &H47    '  abbreviated name for April
    LOCALE_SABBREVMONTHNAME5 = &H48    '  abbreviated name for May
    LOCALE_SABBREVMONTHNAME6 = &H49    '  abbreviated name for June
    LOCALE_SABBREVMONTHNAME7 = &H4A    '  abbreviated name for July
    LOCALE_SABBREVMONTHNAME8 = &H4B    '  abbreviated name for August
    LOCALE_SABBREVMONTHNAME9 = &H4C    '  abbreviated name for September
    LOCALE_SABBREVMONTHNAME10 = &H4D   '  abbreviated name for October
    LOCALE_SABBREVMONTHNAME11 = &H4E   '  abbreviated name for November
    LOCALE_SABBREVMONTHNAME12 = &H4F   '  abbreviated name for December
    LOCALE_SABBREVMONTHNAME13 = &H100F '  abbreviated name for 13th month (if exists)
    LOCALE_SPOSITIVESIGN = &H50        '  positive sign
    LOCALE_SNEGATIVESIGN = &H51        '  negative sign
    LOCALE_IPOSSIGNPOSN = &H52         '  positive sign position
    LOCALE_INEGSIGNPOSN = &H53         '  negative sign position
    LOCALE_IPOSSYMPRECEDES = &H54      '  mon sym precedes pos amt
    LOCALE_IPOSSEPBYSPACE = &H55       '  mon sym sep by space from pos amt
    LOCALE_INEGSYMPRECEDES = &H56      '  mon sym precedes neg amt
    LOCALE_INEGSEPBYSPACE = &H57       '  mon sym sep by space from neg amt

    '#if(WINVER >= 0x0400)
    LOCALE_FONTSIGNATURE = &H58        '  font signature
    LOCALE_SISO639LANGNAME = &H59      '  ISO abbreviated language name
    LOCALE_SISO3166CTRYNAME = &H5A     '  ISO abbreviated country name
    '#endif /* WINVER >= 0x0400 */

    '#if(WINVER >= 0x0500)
    LOCALE_IDEFAULTEBCDICCODEPAGE = &H1012  '  default ebcdic code page
    LOCALE_IPAPERSIZE = &H100A              '  0 = letter, 1 = a4, 2 = legal, 3 = a3
    LOCALE_SENGCURRNAME = &H1007            '  english name of currency
    LOCALE_SNATIVECURRNAME = &H1008         '  native name of currency
    LOCALE_SYEARMONTH = &H1006              '  year month format string
    LOCALE_SSORTNAME = &H1013               '  sort name
    LOCALE_IDIGITSUBSTITUTION = &H1014      '  0 = none, 1 = context, 2 = native digit
    '#endif /* WINVER >= 0x0500 */
End Enum

Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
' Windows API declarations
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As Any) As Long
Private Declare Function GetSystemDefaultLangID Lib "kernel32" () As Integer
Private Declare Function GetLocaleInfoA Lib "kernel32" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpData As Any, ByVal cchData As Long) As Long
Private Declare Function SetLocaleInfoA Lib "kernel32" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpData As Any) As Long

' NT4/Windows 2000 only
Private Declare Function GetLocaleInfoW Lib "kernel32" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpData As Long, ByVal cchData As Long) As Long
Private Declare Function SetLocaleInfoW Lib "kernel32" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpData As Any) As Long
Private Declare Function IsValidLocale Lib "KERNEL32.dll" (ByVal Locale As Long, ByVal dwFlags As Long) As Long
Private Declare Sub CopyMemory Lib "KERNEL32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Declare Function IsTextPointerUnicode Lib "advapi32" Alias "IsTextUnicode" (ByVal lpBuffer As Long, ByVal cb As Long, lpi As Long) As Long

Private Const LOCALE_IDEFAULTANSICODEPAGE As Long = &H1004 ' default ansi code page
Private Const VER_PLATFORM_WIN32s As Long = &H0
Private Const VER_PLATFORM_WIN32_WINDOWS As Long = &H1
Private Const VER_PLATFORM_WIN32_NT As Long = &H2

Private Type OSVERSIONINFO
    dwOSVersionInfoSize  As Long
    dwMajorVersion       As Long
    dwMinorVersion       As Long
    dwBuildNumber        As Long
    dwPlatformId         As Long
    szCSDVersion         As String * 128 ' Maintenance string
End Type
回复 支持 反对

使用道具 举报

发表于 2008-12-26 09:20:10 | 显示全部楼层
运用以上的API定义,区分NT/Win9x系统下调用不同的API,才能真正地解决ANSI/DBCS,UTF7/UFT8/UTF16/UTF32,GB/GBK/BIG相互转化的问题。
回复 支持 反对

使用道具 举报

发表于 2008-12-26 09:23:09 | 显示全部楼层
原帖由 VBAdvisor 于 2008-12-26 09:20 发表
运用以上的API定义,区分NT/Win9x系统下调用不同的API,才能真正地解决ANSI/DBCS,UTF7/UFT8/UTF16/UTF32,GB/GBK/BIG相互转化的问题。

现在谁还用win9X啊
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-12-26 09:24:08 | 显示全部楼层
VBAdvisor ,好像你的代码没发全吧。只有定义,没有实现代码啊。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-12-26 09:27:09 | 显示全部楼层
原帖由 VBAdvisor 于 2008-12-26 09:20 发表
运用以上的API定义,区分NT/Win9x系统下调用不同的API,才能真正地解决ANSI/DBCS,UTF7/UFT8/UTF16/UTF32,GB/GBK/BIG相互转化的问题。


你看到贴里的ASM版代码了吗?翻译过去的VB代码基本上可以使用,但是还是个别转换出现问题,ASM版却没有。
回复 支持 反对

使用道具 举报

发表于 2008-12-26 09:46:37 | 显示全部楼层

FYI :Big2GB/GBK2GB

'用了多年的编码,Cheers!

Public Function BIG2GB(ByVal BIGstring As String) As String

  Dim str As String, STR2 As String

  'Convert BIG5 to GBK first

    str = StrConv(BIGstring, vbFromUnicode, &H804)
    STR2 = StrConv(str, vbUnicode, &H404)

    'Convert GBK to GB2312
    BIG2GB = GBK2GB(STR2)

End Function
Public Function GBK2GB(ByVal CTString As String) As String

  Dim lLen As Long
  Dim CSstring As String

    On Error GoTo ToExit

    If CTString = vbNullString Then Exit Function
    If m_bisNT Then
        lLen = lstrlenW(StrPtr(CTString))
        CSstring = Space$(lLen)
        LCMapStringW &H804, &H2000000, StrPtr(CTString), lLen, StrPtr(CSstring), lLen
        GBK2GB = CSstring
      Else
        lLen = lstrlen(CTString)
        CSstring = Space$(lLen)
        LCMapString &H804, &H2000000, CTString, lLen, CSstring, lLen
        GBK2GB = CSstring
    End If

Exit Function

ToExit:
    GBK2GB = vbNullString

End Function
回复 支持 反对

使用道具 举报

发表于 2008-12-26 09:51:19 | 显示全部楼层
GBK String:
“MsgBox "E郎?岿?"”

GB String:
※MsgBox "E档头错误"§
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

文字版|手机版|小黑屋|VBGood  

GMT+8, 2019-8-19 22:45

VB爱好者乐园(VBGood)
快速回复 返回顶部 返回列表