learn dot microsoft dot com /en-us/windows/win32/api/wbemcli/nf-wbemcli-iwbemclassobject-get
这个页面下的例子代码,是错误的。
文档里写着只有Get()成功才能清理没初始化的变量v,这个代码无条件清理了v。
#include <iostream>
using namespace std;
#include <wbemidl.h>
#pragma comment(lib, "wbemuuid.lib")
//Assumes that pObj is defined as a pointer
// to an IWbemClassObject object.
VARIANT v;
BSTR strClassProp = SysAllocString(L"__CLASS");
HRESULT hr;
hr = pObj->Get(strClassProp, 0, &v, 0, 0);
SysFreeString(strClassProp);
// check the HRESULT to see if the action succeeded.
if (SUCCEEDED(hr) && (V_VT(&v) == VT_BSTR))
{
wprintf(L"The class name is %s\n.", V_BSTR(&v));
}
else
{
wprintf(L"Error in getting specified object\n");
}
VariantClear(&v);
--
FROM 222.130.138.*