dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2013
    Posts
    2

    [RESOLVED] VMI Provider convert out parameters

    Hi,

    I need to use some methods of the WMI Provider but, one method has a non stardard out parameter.
    I am try to convert the out parameters of the function "IWbemServices::ExecMethod", the returned variable "pOutParams" has a CIMTYPE = CIM-ARRAY-OBJECT (8205).
    If i use the function "IWbemClassObject::GetObjectText" I receive the following value:

    [abstract]
    class __PARAMETERS
    {
    [Out, EmbeddedInstance("UWF_ExcludedFile"): ToSubClass, ID(0): DisableOverride ToInstance] UWF_ExcludedFile ExcludedFiles[] = {
    instance of UWF_ExcludedFile
    {
    FileName = "\\MyFolder";
    }};
    [out] uint32 ReturnValue = 0;
    };

    following I post a code snippet:
    Code:
    	// set up to call the Win32_Process::Create method
    	IEnumWbemClassObject *pEnum = NULL;
    	BSTR ObjectName = SysAllocString(L"GetExclusions");
    	BSTR ClassName = SysAllocString(L"UWF_Volume");
    	BSTR bstrQuery = SysAllocString(L"Select * from UWF_Volume");
    
    	hres = pSvc->ExecQuery(_bstr_t(L"WQL"), //Query Language  
    		bstrQuery, //Query to Execute  
    		WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, //Make a semi-synchronous call  
    		NULL, //Context  
    		&pEnum /*Enumeration Interface*/);
    
    	hres = WBEM_S_NO_ERROR;
    
    	ULONG ulReturned;
    	IWbemClassObject *pObj;
    	DWORD retVal = 0;
    
    	//Get the Next Object from the collection  
    	hres = pEnum->Next(WBEM_INFINITE, //Timeout  
    		1, //No of objects requested  
    		&pObj, //Returned Object  
    		&ulReturned /*No of object returned*/);
    
    
    	IWbemClassObject* pClass = NULL;
    	hres = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);
    
    	IWbemClassObject* pInParamsDefinition = NULL;
    	IWbemClassObject* pOutParamsDefinition = NULL;
    	hres = pClass->GetMethod(ObjectName, 0,
    		&pInParamsDefinition, &pOutParamsDefinition);
    	
    	VARIANT pathVariable;
    	VariantInit(&pathVariable);
    
    	hres = pObj->Get(_bstr_t(L"__PATH"),
    		0,
    		&pathVariable,
    		NULL,
    		NULL);
    	printf("\npObj Get returned 0x%x:", hres);
    
    	IWbemClassObject* pOutParams = NULL;
    	if (callType == EXEC_METHOD)
    	{
    		// Execute Method		
    		hres = pSvc->ExecMethod(pathVariable.bstrVal, ObjectName, 0, NULL, NULL, &pOutParams, NULL);
    		
    		VARIANT varReturnValue;
    		hres = pOutParams->Get(_bstr_t(L"ReturnValue"), 0,	&varReturnValue, NULL, 0);
    		
    		CIMTYPE pType;
    		VARIANT value;
    		hres = pOutParams->Get(_bstr_t(L"ExcludedFiles"), 0, &value, &pType, 0);
    		
    		;Value has the CIMTYPE = CIM-ARRAY-OBJECT

    Do You know what do i need to convert this data?

  2. #2
    Join Date
    Apr 2013
    Posts
    2

    Re: VMI Provider convert out parameters

    I found the conversion that I needed.
    I had to access to the data as a SAFEARRAY with the function SafeArrayAccessData,
    retrieve the pointers of the object's interfaces with the function QueryInterface
    and get the property that I needed.

    following I post a code snippet:
    Code:
    if (value.vt != (VT_ARRAY | VT_UNKNOWN))
    {
    	hres = E_FAIL;
    }
    
    if (value.ppunkVal == NULL || *(value.ppunkVal) == NULL)
    {
    	hres = E_FAIL;
    }
    
    CComPtr<IUnknown> * unknown = NULL;
    hres = SafeArrayAccessData(value.parray, (void**)&unknown); // direct access to SA memory
    if (SUCCEEDED(hres))
    {
    	long lLBound, lUBound;  // get array bounds
    	SafeArrayGetLBound(value.parray, 1, &lLBound);
    	SafeArrayGetUBound(value.parray, 1, &lUBound);
    
    	long cElements = lUBound - lLBound + 1;
    	for (int i = 0; i < cElements; ++i)  // iterate through returned objects
    	{
    		CComPtr<IWbemClassObject> spFileName;
    
    		CComPtr<IUnknown> spUnknown = unknown[i];
    
    		hres = spUnknown->QueryInterface(&spFileName);
    
    		if (SUCCEEDED(hres))
    		{
    			variant_t varFileName;
    
    			HRESULT hr = spFileName->Get(L"FileName", 0, &varFileName, 0, 0);
    			if (varFileName.vt != VT_BSTR)
    			{
    				hres = E_FAIL;
    			}
    
    			if (SUCCEEDED(hr))
    			{
    				BSTR myBstr = varFileName.bstrVal;
    			}
    		}
    	}
    	SafeArrayUnaccessData(value.parray);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.