1. Enter big5 characters and return the simplified GB characters
//---------------------------------------------------------------------------
// Function input: big5 characters, returns the simplified GB characters
//---------------------------------------------------------------------------
Ansistring _ fastcall big2gb (ansistring SBIG)
{
Char * pszbig5 = NULL; // big5 encoded character
Wchar_t * wszunicode = NULL; // Unicode-encoded character
Char * pszgbt = NULL; // traditional characters encoded in GB
Char * pszgbs = NULL; // Simplified characters in GB encoding
Ansistring SGB; // The returned string.
Int ilen = 0; // number of characters to be converted
Pszbig5 = SBIG. c_str (); // read the character parameters to be converted
// Calculate the number of characters to convert
Ilen = multibytetowidechar (950, 0, pszbig5,-1, null, 0 );
// Allocate memory to wszunicode
Wszunicode = new wchar_t [ilen + 1];
// Convert the big5 code to the Unicode code. The API function multibytetowidechar is used.
Multibytetowidechar (950, 0, pszbig5,-1, wszunicode, ilen );
// Calculate the number of characters to convert
Ilen = widechartomultibyte (936, 0, (pwstr) wszunicode,-1, null, 0, null, null );
// Allocate memory to pszgbt
Pszgbt = new char [ilen + 1];
// Allocate memory to pszgbs
Pszgbs = new char [ilen + 1];
// Convert the Unicode code to the traditional GB code. Use the API function widechartomultibyte.
Widechartomultibyte (936, 0, (pwstr) wszunicode,-1, pszgbt, ilen, null, null );
// Convert the Gbit/s to simplified Gbit/s. Use the lcmapstring API
Lcmapstring (0x0804, lcmap_simplified_chinese, pszgbt,-1, pszgbs, ilen );
// Return the Simplified characters of the GB code
SGB = pszgbs;
// Release the memory
Delete [] wszunicode;
Delete [] pszgbt;
Delete [] pszgbs;
Return SGB;
}
2. Enter the GB character and return the big5 character
//---------------------------------------------------------------------------
// The function inputs a gb character and returns a big5 character.
//---------------------------------------------------------------------------
Ansistring _ fastcall gb2big (ansistring SGB)
{
Char * pszgbt = NULL; // traditional characters encoded in GB ***
***
Char * pszgbs = NULL; // Simplified characters in GB encoding
Wchar_t * wszunicode = NULL; // Unicode-encoded character
Char * pszbig5 = NULL; // big5 encoded character
Ansistring sbig5; // returned string
Int ilen = 0; // number of characters to be converted
Pszgbs = SGB. c_str (); // read the character parameters to be converted
// Calculate the number of characters to convert
Ilen = multibytetowidechar (936, 0, pszgbs,-1, null, 0 );
// Allocate memory to pszgbt
Pszgbt = new char [ilen * 2 + 1];
// Convert the Gbit/s to the traditional Gbit/s. Use the lcmapstring API
Lcmapstring (0x0804, lcmap_traditional_chinese, pszgbs,-1, pszgbt, ilen * 2 );
// Allocate memory to wszunicode
Wszunicode = new wchar_t [ilen + 1];
// Convert the GB code to the Unicode code. The API function multibytetowidechar is used.
Multibytetowidechar (936, 0, pszgbt,-1, wszunicode, ilen );
// Calculate the number of characters to convert
Ilen = widechartomultibyte (950, 0, (pwstr) wszunicode,-1, null, 0, null, null)