IWbemClassObject::Put failing for a method parameter

V

VJ

MOF file has following definitions,


[
WMI,
guid("{80EBD5B4-3BAF-41f1-9C41-BD36C5282B67}"),
Description("Struct 1") : amended
]
class Struct_1 {


[WmiDataId(1),
Description("Id1") : amended
]
uint32 Id1;


[WmiDataId(2),
Description("Id2") : amended
]
uint32 Id2;


[WmiDataId(3),
Description("Id3") : amended
]
uint32 Id3;


[WmiDataId(4),
Description("Id4") : amended
]
uint32 Id4;



};


[WMI,
Dynamic,
Provider("WmiProv"),
guid("{C944053C-C90F-4012-B775-1F1A261D4BE4}"),
Description("Set values")
]
class Set_Operations {

[key, read]
string InstanceName;


[read]
boolean Active;


//
// Method to set
//
[WmiMethodId(1),
Implemented,
Description("Set Method") : amended,
cpp_quote(
"//\n"
"// Set Method \n"
"// \n"
"//\n"
)
]
void MySetMethod(
[in,
Description("New set")
]
uint32 setval,


[out,
Description("Status of the operation")
]
uint32 Status,


[in,
Description("Struct_1")
]
Struct_1 mystruct[];
);



};
From My application i want to call method MySetMethod


Here is the code snippet,

IWbemClassObject *pIWbemClassObject = NULL;
IWbemClassObject *pInClass = NULL;
IWbemClassObject *pInInst = NULL;
IWbemClassObject *pOutInst = NULL;
IWbemClassObject *pclsToken = NULL; //Struct_1 class
IWbemClassObject *pinstToken = NULL; //Instance of
Struct_1


//
// Get the object and show the class.
//


hr = m_pIWbemServices->GetObject(_bstr_t(L"Set_Operations"),
0,
NULL,
&pIWbemClassObject,
NULL);


if (hr == WBEM_NO_ERROR) {
// Get the input-argument class object and create an instance.


hr = pIWbemClassObject->GetMethod(L"MySetMethod", 0, &pInClass,

NULL);


if (hr == WBEM_NO_ERROR) {
hr = pInClass->SpawnInstance(0, &pInInst);


if (hr == WBEM_NO_ERROR) {
// Set the property.


VARIANT var;
VariantInit(&var);


var.vt = VT_I8;
var.uVal = 1;
hr = pInInst->Put(L"setval", 0, &var, 0);
VariantClear(&var);


//create safearry for Struct_1
SAFEARRAY *psaTokens;
SAFEARRAYBOUND saBounds;


IUnknown *pUnknown = NULL;
LONG idx = 0;


// Define a one dimension array that
contains a single element.
saBounds.cElements = 1;
saBounds.lLbound = 0;


// Create a new variant SafeArray that
contains IUnknown reference
pointers.
psaTokens = SafeArrayCreate(VT_UNKNOWN,
1, &saBounds);


// Get the class definition of the
Struct_1 object.
hr =
m_pIWbemServices->GetObject(_bstr_t(L"Struct_1"),

0,

NULL,

&pclsToken,

NULL);


// Spawn an instance of the Struct_1
object and release the class
// definition object.
pclsToken->SpawnInstance(0,
&pinstToken);
pclsToken->Release();


var.vt = VT_I8;
var.uVal = 1;
pinstToken->Put(_bstr_t(L"Id1"), 0,
&var, 0);
VariantClear(&var);
var.vt = VT_I8;
var.uVal = 2;
pinstToken->Put(_bstr_t(L"Id1"), 0,
&var, 0);
VariantClear(&var);
var.vt = VT_I8;
var.uVal = 3;
pinstToken->Put(_bstr_t(L"Id1"), 0,
&var, 0);
VariantClear(&var);
var.vt = VT_I8;
var.uVal = 4;
pinstToken->Put(_bstr_t(L"v"), 0, &var,
0);
VariantClear(&var);



pinstToken->QueryInterface(IID_IUnknown, (void**)&pUnknown);
SafeArrayPutElement(psaTokens, &idx,
pUnknown);


// Store the object in the variant.
VARIANT vmystruct;
vmystruct.vt = VT_ARRAY | VT_UNKNOWN;
vmystruct.parray = psaTokens;


hr = pInInst->Put(L"mystruct", 0,
&vmystruct, 0);
}
}


But hr = pInInst->Put(L"mystruct", 0, &vmystruct, 0); FAILS.
It says invalid argument/data.
What is wrong here ??
Is there any other way to create safearray of Struct_1
 
V

VJ

After i made hr = pInInst->Put(L"mystruct", 0, &vmystruct, VT_ARRAY) to
hr = pInInst->Put(L"mystruct", 0, &vmystruct, 0) is runs properly.
But m_pIWbemServices->ExecMethod fails with 0x80041008

Am i not passing array ot struct_1 correctly?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top