文章目录
- COM - get VARIANT value - .vt = (VT_BSTR | VT_ARRAY)
- 概述
- 笔记
- END
COM - get VARIANT value - .vt = (VT_BSTR | VT_ARRAY)
概述
取到一个VARIANT值, .vt = 0x2008, 查了一下, 0x2008 = (VT_BSTR | VT_ARRAY)
查了资料, 这个vt = 0x2008是BSTR的数组.
看看咋取值? 网上就没查到啥资料.
去查微软的例子库, 查到了. 封装了一个函数.
还是官方库靠谱, 比网上零散的资料好的太多.
笔记
bool CWmiBase::get_var_VT_BSTR_VT_ARRAY(VARIANT& var, std::wstring& csResut)
{// COM - get VARIANT value - .vt = (VT_BSTR | VT_ARRAY)//! \ref VC2008Samples\MFC\general\VariantUsebool b_rc = false;LONG ary_index_low = 0;LONG ary_index_up = 0;LONG i = 0;HRESULT hr;BSTR* _bstr = NULL;do {csResut.empty();if ((VT_BSTR | VT_ARRAY) != var.vt){_ASSERT(FALSE);break;}if (NULL == var.parray){break;}hr = SafeArrayAccessData(var.parray, (void**)&_bstr); //access the array stored in the varriant.do {if (NULL == _bstr){break;}hr = SafeArrayGetLBound(var.parray, 1, &ary_index_low);if (!SUCCEEDED(hr)){break;}hr = SafeArrayGetUBound(var.parray, 1, &ary_index_up);if (!SUCCEEDED(hr)){break;}for (i = ary_index_low; i <= ary_index_up; i++){csResut += _bstr[i];csResut += TEXT("\n");}} while (false);SafeArrayUnaccessData(var.parray);b_rc = true;} while (false);return b_rc;
}
csResut的结果
Random Access
Supports Writing
SMART Notification