gbk2utf utf2gbk

来源:互联网 发布:广数g76内锥螺纹编程 编辑:程序博客网 时间:2024/06/01 23:03
#include <string>#include <iostream>using namespace std; static void GB23122UTF8( std::string gb2312, std::string& utf8); static void UTF82GB2312( std::string utf8, std::string& gb2312 );


VOID UTF82GB2312( std::string utf8, std::string& gb2312 ){int nLen = MultiByteToWideChar( CP_UTF8, 0, utf8.c_str(), -1, NULL, 0 );USHORT* pwszGB2312 = new USHORT[ nLen + 1 ];RtlZeroMemory( pwszGB2312, nLen * 2 + 2 );MultiByteToWideChar( CP_UTF8, 0, utf8.c_str(), -1, (LPWSTR)pwszGB2312, nLen );nLen = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)pwszGB2312, -1, NULL, 0, NULL, NULL );CHAR* pszGB2312 = new CHAR[ nLen + 1 ];RtlZeroMemory( pszGB2312, nLen + 1 );WideCharToMultiByte( CP_ACP, 0, (LPWSTR)pwszGB2312, -1, pszGB2312, nLen, NULL, NULL );gb2312 = pszGB2312;delete [] pszGB2312;delete [] pwszGB2312;}//// GB2312 convert to UTF8VOID GB23122UTF8( std::string gb2312, std::string& utf8 ){int nLen = MultiByteToWideChar( CP_ACP, 0, gb2312.c_str(), -1, NULL, 0 );USHORT* pwszUTF8 = new USHORT[ nLen + 1 ];RtlZeroMemory( pwszUTF8, nLen * 2 + 2 );MultiByteToWideChar( CP_ACP, 0, gb2312.c_str(), -1, (LPWSTR)pwszUTF8, nLen );nLen = WideCharToMultiByte( CP_UTF8, 0, (LPWSTR)pwszUTF8, -1, NULL, 0, NULL, NULL );CHAR* pszUTF8 = new CHAR[ nLen + 1 ];RtlZeroMemory( pszUTF8, nLen + 1 );WideCharToMultiByte( CP_UTF8, 0, (LPWSTR)pwszUTF8, -1, pszUTF8, nLen, NULL, NULL );utf8 = pszUTF8;delete [] pszUTF8;delete [] pwszUTF8;}

1 0
原创粉丝点击