想把Unicode 转换成WINDOWS支持的编码
这里做了一个实验
        char p[6];
p[0]=p[2]=0x0;
p[1]='a';
p[3]='m';
p[4]='?';
p[5]='v';
然后 LPWSTR tr=new WCHAR[3];
     把p指针指向的Unicode 转换成双字符型变量
然后调用 WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,tr,3,buffer,4,NULL,NULL);
  但是buffer 是空的,为什么?

解决方案 »

  1.   

    用GetLastError看看到底是什么错误,大多是参数不对。
      

  2.   

    先给你一个例子:
    void CWcstombsDlg::OnChange() 
    {
    WCHAR pwc[50];
    wcscpy(pwc, L"你好");
    int i = WideCharToMultiByte(CP_ACP, 0, pwc, -1, NULL, 0, NULL, NULL);
    CHAR * Message_Content = new CHAR[i];
    memset(Message_Content, 0, i);
    WideCharToMultiByte(CP_ACP, 0, pwc, -1, Message_Content,i, NULL, NULL);
    MessageBox(Message_Content);
    delete []Message_Content;
    }
      

  3.   

    把p指针指向的Unicode 转换成双字符型变量
    你的描述我看不懂,这不可以转换的。
    你的代码我就不帮你调试了。
      

  4.   

    void CStringToChar(CString m_snd,char *str2)
    {
    char buf[129]; //发送缓冲区
    ZeroMemory(buf,sizeof(buf)); //缓冲区清零
    CString tmpstr(m_snd); //复制要发送的字符串
    int multibytelen=WideCharToMultiByte( //计算从Unicode转换到Ansi后需要的字节数
            CP_ACP, //根据ANSI code page转换
            WC_COMPOSITECHECK | WC_DEFAULTCHAR, //转换出错用缺省字符代替
            tmpstr.GetBuffer(m_snd.GetLength()), //要转换的字符串地址
    m_snd.GetLength(), //要转换的个数
    0, //转换后字符串放置的地址
    0, //最多转换字符的个数,为0表示返回转换Unicode后需要多少个字节
    0, //缺省的字符:"\0"
    0 //缺省的设置
    );

    WideCharToMultiByte( //转换Unicode到Ansi
    CP_ACP,
    WC_COMPOSITECHECK | WC_DEFAULTCHAR,
    tmpstr.GetBuffer(m_snd.GetLength()),
    m_snd.GetLength(),
    buf, //转换到缓冲区中
    128, //最多128个字节
    0,
    0
    );

    strcpy(str2,buf);
    }
      

  5.   

    这是一个实际的例子,一部分,它不能直接运行。unsigned short *pucRecieveUnicodeData; /* pointer to a buffer that recieves the translated string */
    unsigned short *pucUnicodeDataDivided ; /* pointer to a buffer that recieves the divided string */
    unsigned char  *pucShiftjis;            /* pointer to a buffer that recieves string to be convert unicode to shiftjis */
    int nRemainder; /* the Remainder */
    int nDivideLength1 ; /* the Quotient revised */
    int nDivideLength2 ; /* Quotient */
    int nPosition ; /* start postion of string to divided */
    int nDivideLen = 0;//unicode --> shiftjis
    pucShiftjis = new unsigned char[100];
    memset(pucShiftjis,0,100); int nLen2 = WideCharToMultiByte(CP_ACP,0,pucUnicodeDataDivided,-1,NULL,0,NULL,NULL);
    WideCharToMultiByte(CP_ACP,0,pucUnicodeDataDivided,-1,(char*)pucShiftjis,nLen2,NULL,NULL); y+=20;
        pDC.TextOut(x,y,pucShiftjis);