用_T()宏包含你的字符串,如:_T("Hello,World!")

解决方案 »

  1.   

    用_T()是个好习惯,比如说给一个CString串赋值.
      

  2.   

    这里有几种方法:
    1. 常量字串,应采用zhanghy(zhanghy)的方法:将字串以L作为前导,如 L"abc"
    2. char*型字串,则需要转换,方法有三
     1) 使用USECONVERTION宏和A2W宏
     2) 当使用C++.net时,直接用CA2W模板,如:CA2W(__str)
     3) 使用转换函数MultiByteToWideChar,如:(这里考虑对Ascii以外的字符集)
    // we want to convert an MBCS string in lpszA
    int nLen = MultiByteToWideChar(CP_ACP, 0,lpszA, -1, NULL, NULL);
    LPWSTR lpszW = new WCHAR[nLen];
    MultiByteToWideChar(CP_ACP, 0, 
       lpszA, -1, lpszW, nLen);
    // use it to call OLE here
    pI->SomeFunctionThatNeedsUnicode(lpszW);
    // free the string
    delete[] lpszW;
      

  3.   

    对了, 补充一下
    DWORD GetAdapterIndex(
      LPWSTR AdapterName,  // name of the adapter :这里
      PULONG IfIndex       // index of the adapter
    );已经得到
    AdapterName=“{02..}”;
    看来要两步转换??
      

  4.   

    在MFC中简单一点是:
    CString str1="?????";
    BSTR bstr1=str1.AllocSysString();
    .......
    FreeSysString(bstr1);
      

  5.   

    已有char s[30],要转换成WCHAR ws[30],
    用:
    swprintf(ws,L"%S",s);  //和sprintf的用法差不多
      

  6.   

    char *pchData = "我";
    wchar_t *pwchData = new wchar_t[2];
    MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,pchData,-1,pwchData,strlen(pchData)+1);
      

  7.   

    还可以用到ATL里的辅助函数void func( LPSTR lpsz )
    {
       USES_CONVERSION;
       ...
       LPWSTR x = A2W(lpsz)
       // Do something with x
       ...
    }头文件可能是atl.h或者atlbase.h没有查,自己找找看