我的程序必须要在,_UNICODE下编译。
例如我有一个变量
CString str;
str="a中国b";
则str.GetLength()返回的长度是4,
而str.Left(2)的结果是"a中"
如上的变量str如果转换成char数组。
急用!!!!
我试过,如果不是用双子节,则str.GetLength()返回的是6,
这个时候使用如下的方式
char cc[10];
memset(cc,0,10);
int i;
for(i=0;i<str.GetLength();i++)
    cc[i] = str.GetAt(i);
可以正常转换
或则使用
strncpy(cc,str,str.GetLength());
也可以!
但在UNICODE下就不行!!

解决方案 »

  1.   

    WideCharToMultiChar(...)好像是这个函数
      

  2.   

    试试:
    char cc[10]cc=str.AllocSysString()
      

  3.   

    AllocSysString()函数返回BSTR其实就还是LPTSTR
    to c0der() :
    调用WideCharToMultiChar函数的时候出现错误
    例如我有一个CString s;
    s = "a中国b";
    char d[10];
    memset(d,0,10);
    int xx = ::WideCharToMultiByte(CP_ACP, WC_DEFAULTCHAR, (LPCTSTR)s, -1, d, 10, NULL, NULL); 
    调用后函数的返回值xx = 0,调用GetLastError()返回87,在错误代码表中87表示
    The parameter is incorrect
    我几乎将前两个参数都试了(在MSDN中查的),不是87就是1004。该如何调用这个函数呀?