//---------------------------------------------------------------------------
// 大五码Big5转GBK码:
void __fastcall BIG52GBK(char *szBuf)
{
if (!strcmp(szBuf, ""))
return;
int nStrLen = strlen(szBuf);
wchar_t *pws = new wchar_t[nStrLen + ];
try
{
int nReturn = MultiByteToWideChar(, , szBuf, nStrLen, pws, nStrLen + );
BOOL bValue = false;
nReturn = WideCharToMultiByte(, , pws, nReturn, szBuf, nStrLen + , "?", &bValue);
szBuf[nReturn] = ;
}
__finally
{
delete[] pws;
}
}
//---------------------------------------------------------------------------
// GBK转大五码(Big5)
void __fastcall GBK2BIG5(char *szBuf)
{
if(!strcmp(szBuf, ""))
return ;
int nStrLen = strlen(szBuf);
wchar_t *pws = new wchar_t[nStrLen + ];
try
{
MultiByteToWideChar(, , szBuf, nStrLen, pws, nStrLen + );
BOOL bValue = false;
WideCharToMultiByte(, , pws, nStrLen, szBuf, nStrLen + , "?", &bValue);
szBuf[nStrLen] = ;
}
__finally
{
delete[] pws;
}
}
//----------------------------------------------------------------------------
// GB2312码转GBK码
void __fastcall GB2GBK(char *szBuf)
{
if(!strcmp(szBuf, ""))
return;
int nStrLen = strlen(szBuf);
WORD wLCID = MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_PRC);
int nReturn = LCMapString(wLCID, LCMAP_TRADITIONAL_CHINESE, szBuf, nStrLen, NULL, );
if(!nReturn)
return;
char *pcBuf = new char[nReturn + ];
try
{
wLCID = MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_PRC);
LCMapString(wLCID, LCMAP_TRADITIONAL_CHINESE, szBuf, nReturn, pcBuf, nReturn + );
strncpy(szBuf, pcBuf, nReturn);
}
__finally
{
delete[] pcBuf;
}
}
//---------------------------------------------------------------------------
// GBK码转GB2312码
void __fastcall GBK2GB(char *szBuf)
{
if(!strcmp(szBuf, ""))
return;
int nStrLen = strlen(szBuf);
WORD wLCID = MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_BIG5);
int nReturn = LCMapString(wLCID, LCMAP_SIMPLIFIED_CHINESE, szBuf, nStrLen, NULL, );
if(!nReturn)
return;
char *pcBuf = new char[nReturn + ];
try
{
wLCID = MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_BIG5);
LCMapString(wLCID, LCMAP_SIMPLIFIED_CHINESE, szBuf, nReturn, pcBuf, nReturn + );
strncpy(szBuf, pcBuf, nReturn);
}
__finally
{
delete []pcBuf;
}
}