但論壇裡經常有人問如何在自己的程序中集成這些功能呢?本文將介紹如何利用 Windows 提供的API 函數來實現
本文將介紹四個轉換函數分別實現如下的轉換
* Big
* GBK => Big
* GB
* GBK => GB
有關 GB
// Big
void BIG
{
if(!strcmp(szBuf
return;
int nStrLen = strlen(szBuf);
wchar_t *pws = new wchar_t[nStrLen +
try
{
int nReturn = MultiByteToWideChar(
BOOL bValue = false;
nReturn = WideCharToMultiByte(
szBuf[nReturn] =
}
__finally
{
delete[] pws;
}
}
//
// GBK => Big
void GBK
{
if(!strcmp(szBuf
return ;
int nStrLen = strlen(szBuf);
wchar_t *pws = new wchar_t[nStrLen +
__try
{
MultiByteToWideChar(
BOOL bValue = false;
WideCharToMultiByte(
szBuf[nStrLen] =
}
__finally
{
delete[] pws;
}
}
//
// GB
void GB
{
if(!strcmp(szBuf
return;
int nStrLen = strlen(szBuf);
WORD wLCID = MAKELCID(MAKELANGID(LANG_CHINESE
int nReturn = LCMapString(wLCID
if(!nReturn)
return;
char *pcBuf = new char[nReturn +
__try
{
wLCID = MAKELCID(MAKELANGID(LANG_CHINESE
LCMapString(wLCID
strncpy(szBuf
}
__finally
{
delete[] pcBuf;
}
}
//
// GBK =〉GB
void GBK
{
if(!strcmp(szBuf
return;
int nStrLen = strlen(szBuf);
WORD wLCID = MAKELCID(MAKELANGID(LANG_CHINESE
int nReturn = LCMapString(wLCID
if(!nReturn)
return;
char *pcBuf = new char[nReturn +
__try
{
wLCID = MAKELCID(MAKELANGID(LANG_CHINESE
LCMapString(wLCID
strncpy(szBuf
}
__finally
{
delete []pcBuf;
}
}
// 調用示例
char sourceEncode[
char szBuf[
// 從 GB
strcpy(szBuf
GB
// 從GB
strcpy(szBuf
GB
GBK
}
From:http://tw.wingwit.com/Article/program/net/201311/12393.html