UTF8ToBytes

  // TODO: 在此处为应用程序的行为编写代码。
        byte src[] = {(byte)228,(byte)184,(byte)173,(byte)229,(byte)155,(byte)189,0};  //中国

        int ucCharLen = MultiByteToWideChar(CP_UTF8,0,(LPCSTR)src,-1,NULL,0);
        LPWSTR wbuf = new WCHAR[ucCharLen];
        memset(wbuf,0,sizeof(wbuf));
        MultiByteToWideChar(CP_UTF8,0,(LPCSTR)src,-1,wbuf,ucCharLen);

        byte* buf = NULL;

        int byteLength = WideCharToMultiByte(CP_UTF8,0,(LPCWSTR)wbuf,-1,NULL,0,NULL,NULL);
        buf = new byte[byteLength];
        memset(buf,0,sizeof(buf));
        WideCharToMultiByte(CP_UTF8,0,(LPCWSTR)wbuf,-1,(LPSTR)buf,byteLength,NULL,NULL);

        delete buf;
        delete wbuf;

posted @ 2006-04-19 23:25  阿牛  阅读(494)  评论(0编辑  收藏  举报