70,033
社区成员
 发帖
 与我相关
 我的任务
 分享#include <Windows.h>
#define CODE_PAGE_GB18030 54936
int Unicode2GBK( wchar_t *pUnicode, char** ppDest)
{
    // get the size of the dest string 
    const int size = ::WideCharToMultiByte( CODE_PAGE_GB18030, 
        0/* you can do more for it*/, pUnicode, -1, 0, 0, 0, 0 ); 
    if ( size == 0 )
    {
        return -1;
    }
    char* pDestString = new char[size + 2];        
       ::memset( pDestString, 0, sizeof(pDestString) );
    // transform
    int ret = ::WideCharToMultiByte( CODE_PAGE_GB18030, 0, pUnicode, -1, pDestString, size, 0, 0 ); 
    if( ret == 0 )
    {
        delete pDestString;
        return -1;
    }
    else
    {
        *ppDest = pDestString;
        return 0;
    }
}