BSTR bstrstr;//这是你要转换的BSTR变量
LPCOLESTR szFromBSTR;
szFromBSTR=bstrstr;
int nLen;
nLen=WideCharToMultiByte(CP_ACP,0,szFromBSTR,-1,NULL,NULL,NULL,NULL)
LPSTR szNewStdString;//这是转换的结果变量
szNewStdString=(char)malloc(nLen);
WideCharToMultiByte(CP_ACP,0,szFromBSTR,-1,szNewStrString,nLen,NULL,NULL);
//就这样.

解决方案 »

  1.   

    如果使用_bstr_t , 问题就很轻松!
    #include<comdef.h>BSTR bsYourString;
    ....
    _bstr_t bstrYourString = bsYourString;CString str = (LPCTSTR)bstrYourString;
    or
    LPCTSTR lpszStr = (LPCTSTR)bstrYourString;
      

  2.   

    用AnsiToUnicode()和UnicodeToAnsi()两个函数进行相互转换。
      

  3.   

    还有:
    #include"comutil.h"
    {
           char sz[]="hello";
           _bstr_t b;
           b = _com_util::ConvertStringToBSTR(sz);
           char * p = _com_util::ConvertBSTRToString(b);
     }