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);2,
如果使用_bstr_t , 问题就很轻松!
#include<comdef.h>BSTR bsYourString;
....
_bstr_t bstrYourString = bsYourString;CString str = (LPCTSTR)bstrYourString;
or
LPCTSTR lpszStr = (LPCTSTR)bstrYourString; 3,
#include"comutil.h"
{
char sz[]="hello";
_bstr_t b;
b = _com_util::ConvertStringToBSTR(sz);
char * p = _com_util::ConvertBSTRToString(b);
}
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);2,
如果使用_bstr_t , 问题就很轻松!
#include<comdef.h>BSTR bsYourString;
....
_bstr_t bstrYourString = bsYourString;CString str = (LPCTSTR)bstrYourString;
or
LPCTSTR lpszStr = (LPCTSTR)bstrYourString; 3,
#include"comutil.h"
{
char sz[]="hello";
_bstr_t b;
b = _com_util::ConvertStringToBSTR(sz);
char * p = _com_util::ConvertBSTRToString(b);
}
http://www.csdn.net/expert/TopicView.asp?id=316376