本文介绍了VMI Provider转换出参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要使用WMI提供程序的一些方法,但是,一种方法有一个非标准输出参数。

我试图转换函数"IWbemServices :: ExecMethod"的输出参数,返回的变量"pOutParams"和有一个CIMTYPE = CIM_ARRAY | CIM_OBJECT(8205)。

如果我使用函数"IWbemClassObject :: GetObjectText"我收到以下价值:



[摘要]

类__PARAMETERS

{

[Out,EmbeddedInstance(" UWF_ExcludedFile"):ToSubClass,ID(0):DisableOverride ToInstance] UWF_ExcludedFile ExcludedFiles [] = {

UWF_ExcludedFile的实例

{

FileName =" \\MyFolder" ;;

}};
$
[out] uint32 ReturnValue = 0;

};
$


我发布了一个代码片段:

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 | CIM_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:

// 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 | CIM_OBJECT (8205)


你知道我需要转换这些数据吗?


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

推荐答案

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);
}






这篇关于VMI Provider转换出参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:03