Re: Accessing data in embedded class object WMI ACPI sample from DDK

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Ivan Brugiolo [MSFT] (ivanbrug_at_online.microsoft.com)
Date: 06/16/04


Date: Tue, 15 Jun 2004 17:40:47 -0700

An embedded object is, form the COM C++ point of view, a pointer
to an IWbemClassObject implementation that you pass as a VT_UNKNOWN to
the VARIANT you pass to the Put method.

-- 
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"MichaelMc2" <MichaelMc2@discussions.microsoft.com> wrote in message
news:9D1DF53D-935E-4EC3-A915-6BD9BA275900@microsoft.com...
> Hello,
> I am currently working on trying to Execute a Method on the
AcpiTest_MPackage class that was provided in the Windows DDK.
C:\winddk\src\wdm\wmi\wmiacpi\acpimof.mof
>
> If you are familiar with the .mof code for that sample, the
AcpiTest_MPackage has two methods (GetPackage and SetPackage) which get and
set the properties of a Package class object. The Package class object has
as it's property an array.
>
> We are interested in getting and setting values in this array for use in
our program. I am having trouble with using IwbemServices::ExecMethod. I can
execute the SetPackage or GetPackage methods but am confused about how to
get and set the Array that is a property of Package since Package is
embedded in the AcpiTest_MPackage class.
>
> Once I use ExecMethod,  I have a pointer to my AcpiTest_MPackage object in
or out parameters respectively, but how do I get and set the array that is
inside the Data property, which is a Package object.
>
> Below is some sample code from my project:
> In the case of executing GetPackage method:
>
> const BSTR SMnixInst =
SysAllocString(L"AcpiTest_MPackage.InstanceName=\"ACPI\\\\PNP0C14\\\\0_0\"")
;
>
> const BSTR PackageInst =
SysAllocString(L"Package.InstanceName=\"ACPI\\\\PNP0C14\\\\0_0\"");
>
> BSTR MethodName = SysAllocString(L"SetPackage");
> BSTR MethodName1 = SysAllocString(L"GetPackage");
> const BSTR bSetPack =  SysAllocString(L"SetPackage");
> const BSTR bGetPack =  SysAllocString(L"GetPackage");
>
> //GET using GetPackage Method
>
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////
>   // Get the class definition for AcpiTest_MPackage, which contains
> hres = pSvc->GetObject(SMnix, 0, NULL, &pSMnixInst, NULL);
> if(hres != WBEM_S_NO_ERROR)
> AfxMessageBox(_T("Failed to get AcpiTest_MPackage"));
>
> // Get the GetPackage's in parameter object.
> hres = pSMnixInst->GetMethod(MethodName1, 0, &pdefInParams,
&pdefOutParams);
> if(hres != WBEM_S_NO_ERROR)
> AfxMessageBox(_T("Failed to get GetPackage In Parameters"));
> if(hres == WBEM_E_OUT_OF_MEMORY)
> AfxMessageBox(_T("WBEM_E_OUT_OF_MEMORY"));
>
> // Execute the GetPackage method. The method is passed the out parameter
> hres = pSvc->ExecMethod(SMnixInst, bGetPack, 0, NULL, pinstInParams,
&pinstOutParams, NULL);
> if(hres != WBEM_S_NO_ERROR)
> AfxMessageBox(_T("Failed in Exec Method"));
>
> //Get the Data property of AcpiTest_MPackage
> hres = pinstOutParams->Get(
>             bData, // Data Property
>             lFlags,
>             &getObject, // output Package to this variant
>             NULL,
>             NULL);
>
> At this point I need to somehow get the array out of my Package object
which is apparently in the Variant getObject from this last call above.
>
> Likewise for SetPackage I will need to build an array in a Package object,
use IwbemClassObject::Put to but the array into the Bytes property and then
somehow Put that Package Object into the Data property of AcpiTest_MPackage'
s SetPackage method.
>
> I have gotten to this point:
>
>
//**************************************************************************
**************************
> /////////////////// Getting the AcpiTest_MPackage Instance and Executing
Set Method.//////////////////
>
//**************************************************************************
**************************
>
>
> hres = pSvc->GetObject(PackageInst, 0, NULL, &pPackage, NULL);
> if(hres != WBEM_S_NO_ERROR)
> AfxMessageBox(_T("Failed to get PackageInst"));
>
>
> // Store the array in the Bytes property.
> hres = pPackage->Put(bBytes, 0, &rcvElements, 0);
> if(hres != WBEM_S_NO_ERROR)
> AfxMessageBox(_T("Failed to PUT PackageInst"));
>
> //Put Instance in WMI repository
> hres = pSvc->PutInstance(pPackage, lFlags2, NULL, NULL);
> if(hres != WBEM_S_NO_ERROR)
> {
> AfxMessageBox(_T("Put Instance Failed"));
> }
>
>     AfxMessageBox(_T("Put Package done, new Array Set"));
>
>
>
> // Get the class definition for AcpiTest_MPackage, which contains
> hres = pSvc->GetObject(SMnix, 0, NULL, &pSMnixInst, NULL);
> if(hres != WBEM_S_NO_ERROR)
> AfxMessageBox(_T("Failed to get SMnixInst"));
>
> // Get the SetMethod's in parameter object.
> hres = pSMnixInst->GetMethod(MethodName, 0, &pdefInParams,
&pdefOutParams);
> if(hres != WBEM_S_NO_ERROR)
> AfxMessageBox(_T("Failed to get SetPackage In Parameters"));
> if(hres == WBEM_E_OUT_OF_MEMORY)
> AfxMessageBox(_T("WBEM_E_OUT_OF_MEMORY"));
>
> //Spawn Instance of AcpiTest_MPackage
> hres = pdefInParams->SpawnInstance(0, &pinstInParams);
> if(hres != WBEM_S_NO_ERROR)
> AfxMessageBox(_T("Failed in SpawnInstance"));
> if(hres == WBEM_S_NO_ERROR)
> AfxMessageBox(_T("NoError in SpawnInstance"));
>
> //PUT PACKAGE
SOMEHOW*********************************************************************
*********
> // Store the embedded object array in the Data property.
> //pinstInParams->Put(bData, 0, need Package class in a Variant here to use
Put, 0);
>
> // Execute the SetPackage method. The method is passed the in parameter
> hres = pSvc->ExecMethod(SMnixInst, bSetPack, 0, NULL, pinstInParams,
&pinstOutParams, NULL);
> if(hres != WBEM_S_NO_ERROR)
> AfxMessageBox(_T("Failed in Exec Method"));
> if(hres == WBEM_E_INVALID_PARAMETER)
> AfxMessageBox(_T("WBEM_E_INVALID_PARAMETER"));
> if(hres == WBEM_E_INVALID_METHOD_PARAMETERS)
> AfxMessageBox(_T("WBEM_E_INVALID_METHOD_PARAMETERS"));
>


Relevant Pages