locked
How do I set the input values of an object into the Put method RRS feed

  • Question

  • void HyperVVM::CreateSnapshot()
    {
        CComPtr<IWbemClassObject> pInParams;
        CComPtr<IWbemClassObject> pOutParameters;
        this->GetMethodParams(L"Msvm_VirtualSystemSnapshotService", L"CreateSnapshot", &pInParams);

        VARIANT affectedSystem;

       //m_pVmWbemClassObject is my IWBemClassObject* containing the instance of the VM that I want to do snapshot

      /* How can I set the affectedSystem input paramter?

     uint32 CreateSnapshot(
    
      [in]      CIM_ComputerSystem           REF AffectedSystem,
      [in]      string                           SnapshotSettings,
      [in]      uint16                           SnapshotType,
      [in, out] CIM_VirtualSystemSettingData REF ResultingSnapshot,
      [out]     CIM_ConcreteJob              REF Job
    );

    // In the above method how can set AffectedSystem and ResultingSnapshot Rereences

        CHK_HRES(pInParams->Put(L"AffectedSystem", 0, &pAffectedSystem, 0));
        CHK_HRES(pInParams->Put(L"AffectedSystem", 0, &CComVariant(m_pVmWbemClassObject), 0));

        CHK_HRES(pInParams->Put(L"SnapshotType", 0, &CComVariant(L"2"), 0));
        CHK_HRES(pInParams->Put(L"SnapshotSettings", 0, &CComVariant(L""), 0));

        IWbemClassObject* pSettingsData = NULL;
        CHK_HRES(m_pWbemServices->GetObject(L"Msvm_VirtualSystemGlobalSettingData", 0, NULL, &pSettingsData, NULL));
        CHK_HRES(pSettingsData->Put(L"ElementName", 0 , &CComVariant(L"rhel-1"), 0));
        CHK_HRES(pInParams->Put(L"ResultingSnapshot", 0, &CComVariant(pSettingsData), 0));

        this->ExecMethod(m_pVmWbemClassObject, L"CreateSnapshot", pInParams, &pOutParameters);
    }

    void HyperVVM::GetMethodParams(LPCWSTR pObjectPath,
                                                LPCWSTR pMethodName,
                                                IWbemClassObject **ppInParams)
    {
        CComPtr<IWbemClassObject> pClass;
        CComPtr<IWbemClassObject> pInParamsDefinition;

        CHK_HRES(m_pWbemServices->GetObject(CComBSTR(pObjectPath), 0, NULL, &pClass, NULL));
        CHK_HRES(pClass->GetMethod(pMethodName, 0, &pInParamsDefinition, NULL));
        CHK_HRES(pInParamsDefinition->SpawnInstance(0, ppInParams));
    }

    void HyperVVM::ExecMethod(IWbemClassObject *pObject,
                                           LPCWSTR pMethodName,
                                           IWbemClassObject *pInParams,
                                           IWbemClassObject **ppOutParams)
    {
        CComBSTR path(this->GetStrProperty(L"__PATH", pObject));

        
        CHK_HRES(m_pWbemServices->ExecMethod(path,
                                             CComBSTR(pMethodName),
                                             0,
                                             NULL,
                                             pInParams,
                                             ppOutParams,
                                             NULL));
    }

        
    Friday, April 6, 2018 8:34 AM

Answers