Getting Error Source Information for a Specific Error Source
A user-mode application can get information about a particular error source that is supported by the hardware platform by calling the WHEAErrorSourceMethods::GetErrorSourceInfoRtn method. This method returns a WHEA_ERROR_SOURCE_DESCRIPTOR structure that describes the specified error source.
The following code example shows how to get the error source information for a particular error source.
IWbemServices *pIWbemServices;
ULONG ErrorSourceID;
BSTR ClassName;
BSTR MethodName;
HRESULT Result;
IWbemClassObject *pClass;
IWbemClassObject *pInParametersClass;
IWbemClassObject *pInParameters;
IWbemClassObject *pOutParameters;
VARIANT Parameter;
ULONG Status;
ULONG Length;
SAFEARRAY *Array;
PWHEA_ERROR_SOURCE_DESCRIPTOR ErrorSourceInfo;
// The following example assumes that the application
// has previously connected to WMI on the local machine
// and that the pIWbemServices variable contains the
// pointer that was returned from the call to the
// IWbemLocator::ConnectServer method.
// The following also assumes that the ErrorSourceID
// variable has previously been initialized with the
// identifier of the error source to be queried.
// Specify the class and method to execute
ClassName = SysAllocString(L"WHEAErrorSourceMethods");
MethodName = SysAllocString(L"GetErrorSourceInfoRtn");
// Get the class object for the method definition
Result =
pIWbemServices->GetObject(
ClassName,
0,
NULL,
&pClass,
NULL
);
// Get the input parameter class object for the method
Result =
pClass->GetMethod(
MethodName,
0,
&pInParametersClass,
NULL
);
// Create an instance of the input parameter class
Result =
pInParametersClass->SpawnInstance(
0,
&pInParameters
);
// Set the ErrorSourceId parameter
Parameter.vt = VT_UI4;
Parameter.ulVal = ErrorSourceId;
Result =
pInParameters->Put(
L"ErrorSourceId",
0,
&Parameter,
0
);
VariantClear(&Parameter);
// Call the GetErrorSourceInfoRtn method indirectly
// by calling the IWbemServices::ExecMethod method.
Result =
pIWbemServices->ExecMethod(
ClassName,
MethodName,
0,
NULL,
&pInParameters,
&pOutParameters,
NULL
);
// Get the status from the output parameters object
Result =
pOutParameters->Get(
L"Status",
0,
&Parameter,
NULL,
NULL
);
Status = Parameter.ulval;
VariantClear(&Parameter);
// Get the length from the output parameters object
Result =
pOutParameters->Get(
L"Length",
0,
&Parameter,
NULL,
NULL
);
Length = Parameter.ulval;
VariantClear(&Parameter);
// Get the data buffer from the output parameters object
Result =
pOutParameters->Get(
L"ErrorSourceInfo",
0,
&Parameter,
NULL,
NULL
);
Array = Parameter.parray;
// Get access to the data buffer
Result =
SafeArrayAccessData(
Array,
&ErrorSourceInfo
);
// Process the error source information.
...
// If the error source information is to be saved
// for later use, the data in the ErrorSourceInfo
// structure must be copied to an application-allocated
// WHEA_ERROR_SOURCE_DESCRIPTOR structure before
// freeing up the resources.
...
// Free the array containing the error source information
SafeArrayUnaccessData(Array);
VariantClear(&Parameter);
// Free up resources
SysFreeString(ClassName);
SysFreeString(MethodName);
pInParameters->Release();
pInParametersClass->Release();
pClass->Release();
pOutParameters->Release();