_bstr_t在VC中是为了兼容BSTR类型而增加的,也就是为了实现LPCSTR与BSTR转换。
它需要头文件#include <comdef.h>
_bstr_t 是BSTR的包装类
转换方法
LPSTR strDemo="Test";
_bstr_t bstr(strDemo);
建议加上try,catch,用于catch(_com_error &e)
The following pseudocode shows the typical use of CComBSTR:
HRESULT CMyObject::MyMethod(IOtherObject* pSomething)
{
CComBSTR bstrText(L"Hello");
bstrText += " again"; // LPCSTR conversion
bstrText.ToUpper();
pSomething->Display(bstrText); // [in] parameter
MessageBoxW(0, bstrText, L"Test", MB_OK); // Assumes Windows NT
}
As you can see, CComBSTR significantly simplifies the use of BSTRs. Four uses of CComBSTR, however, require special care:
|
_bstr_t在VC中被引入以实现LPCSTR与BSTR类型的转换,简化了BSTR的使用。本文详细介绍了_bstr_t的用法及注意事项,包括如何避免内存泄漏等问题。
278

被折叠的 条评论
为什么被折叠?



