VARIANT,BSTR,wstring互转

wstring转BSTR和VARIANT

wstring str=L"haha";
BSTR bstr = SysAllocString(str.c_str());
VARIANT var;
var.vt = VT_BSTR;
var.bstrVal = bstr;

BSTR和VARIANT转wstring

BSTR bstr = L"hahah";
VARIANT var;
var.vt = VT_BSTR;
var.bstrVal = L"bbbb";

wstring str = (_bstr_t)bstr;
wstring str2 = (_bstr_t)var.bstrVal;

你可能感兴趣的:(VARIANT,BSTR,wstring互转)