描述:
如题
解决方案1:
为了不让你的组件漏洞,最好用这个: //分我就不要了,给前面那些仁兄吧!
//------------------------//
// Convert BSTR to char * //转换后的char*用完后通过delete []删除
//------------------------//
inline char* ConvertBSTRToString(BSTR pSrc)
{
if(!pSrc) return NULL;
//convert even embeded NULL
DWORD cb,cwch = ::SysStringLen(pSrc);
char *szOut = NULL;
if(cb = ::WideCharToMultiByte(CP_ACP, 0,
pSrc, cwch + 1, NULL, 0, 0, 0))
{
szOut = new char[cb];
if(szOut)
{
szOut[cb - 1] = '\0';
if(!::WideCharToMultiByte(CP_ACP, 0,
pSrc, cwch + 1, szOut, cb, 0, 0))
{
delete []szOut;//clean up if failed;
szOut = NULL;
}
}
}
return szOut;
};