I'm trying to invoke a certain WMI method using C++: Msvm_VirtualSystemManagementService::GetVirtualSystemThumbnailImage (https://learn.microsoft.com/en-us/previous-versions/windows/desktop/virtual/getvirtualsystemthumbnailimage-msvm-virtualsystemmanagementservice).
The method itself requires three parameters: a reference to an instance of CIM_VirtualSystemSettingData, and two uint16s.
In C++, invoking a WMI method first requires you to obtain the the parameters for a method via IWbemClassObject::GetMethod and SpawnInstance; at this point, you can then start using the IWbemClassObject::Put method to begin filling out the parameters, i.e.:
CComVariant varCommand2;
varCommand2.vt = VT_BSTR;
varCommand2.bstrVal = _bstr_t("32");
hres = pClassInstance->Put(L"WidthPixels", 0, &varCommand2, CIM_UINT16);
This works fine. However, I am unable to find any documentation whatsoever with regard to passing an instance of a CIM class. The documentation on on IWbemClassObject::Put states:
If pVal is to contain an embedded IWbemClassObject, the caller must call IWbemClassObject::QueryInterface for IID_IUnknown and place the resulting pointer in the VARIANT using a type of VT_UNKNOWN.
As such, this is what I am trying to do:
CComVariant varCommand;
varCommand.vt = VT_UNKNOWN;
vVirtualSystemSettingData[0].getClassInstance()->QueryInterface(IID_IUnknown, (void**)&varCommand); //getClassInstance returns a reference to the CComPtr that contains the VirtualSystemSettingData I want to use
hres = pClassInstance->Put(L"TargetSystem", 0, &varCommand, 0);
Unfortunately, I simply get a mismatch error, so I know I am not doing this correctly. Ergo, does anyone know how to pass references of CIM objects to the IWbemClassObject::Put method?
Kind regards!