GBK中文繁簡轉換函式

lt發表於2016-12-13

按照這篇部落格這篇部落格改寫的

#include <stdio.h>
#include <windows.h>
#include <assert.h>
#include <tchar.h>
char * f2j(const char* a,char *b )
{
  TCHAR *szOutBuffer=b;//[128+1] = {0};
  WORD wLanguageID = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED);
  LCID Locale = MAKELCID(wLanguageID, SORT_CHINESE_PRCP);
  int iRet = LCMapString(Locale,
      LCMAP_SIMPLIFIED_CHINESE,
      _T(a), -1,
      szOutBuffer, 128*sizeof(TCHAR));
  if(iRet == 0)
  {
    DWORD dwErr = GetLastError();
    assert(0);
  }
  return szOutBuffer;
  //assert( _tcscmp(szOutBuffer, _T("")) == 0 );
}
char * j2f(const char* a,char *b)
{
  TCHAR *szOutBuffer=b;//[128+1] = {0};
  WORD wLanguageID = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED);
  LCID Locale = MAKELCID(wLanguageID, SORT_CHINESE_PRCP);
  int iRet = LCMapString(Locale,
    LCMAP_TRADITIONAL_CHINESE,
    _T(a), -1,
    szOutBuffer, 128*sizeof(TCHAR));
  if(iRet == 0)
  {
    DWORD dwErr = GetLastError();
    assert(0);
  }
  return szOutBuffer;  
  //assert( _tcscmp(szOutBuffer, _T("")) == 0 );
}
int main()
{
char b[1000];
printf(f2j("中國亞洲",b));
printf(j2f("荷蘭歐洲",b));
return 0;
}

--輸出
中國亞洲荷蘭歐洲

參考資料LCMapString

相關文章