Obtendo informações de origem do erro para todas as fontes de erro
Um aplicativo no modo de usuário pode obter informações sobre todas as fontes de erro no sistema chamando o método WHEAErrorSourceMethods::GetAllErrorSourcesRtn . Esse método retorna uma matriz de estruturas de WHEA_ERROR_SOURCE_DESCRIPTOR que descreve todas as fontes de erro compatíveis com a plataforma de hardware.
O exemplo de código a seguir mostra como obter as informações de origem do erro para todas as fontes de erro no sistema.
IWbemServices *pIWbemServices;
BSTR ClassName;
BSTR MethodName;
HRESULT Result;
IWbemClassObject *pOutParameters;
VARIANT Parameter;
ULONG Status;
ULONG Count;
ULONG Length;
SAFEARRAY *Array;
PWHEA_ERROR_SOURCE_DESCRIPTOR ErrorSourceList;
// 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.
// Specify the class and method to execute
ClassName = SysAllocString(L"WHEAErrorSourceMethods");
MethodName = SysAllocString(L"GetAllErrorSourcesRtn");
// Call the GetAllErrorSourcesRtn method indirectly
// by calling the IWbemServices::ExecMethod method.
Result =
pIWbemServices->ExecMethod(
ClassName,
MethodName,
0,
NULL,
NULL,
&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 count from the output parameters object
Result =
pOutParameters->Get(
L"Count",
0,
&Parameter,
NULL,
NULL
);
Count = 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"ErrorSourceArray",
0,
&Parameter,
NULL,
NULL
);
Array = Parameter.parray;
// Get access to the data buffer
Result =
SafeArrayAccessData(
Array,
&ErrorSourceList
);
// Process the error source information.
...
// If the error source information is to be saved
// for later use, the data in the ErrorSourceList
// array must be copied to an application-allocated
// array of WHEA_ERROR_SOURCE_DESCRIPTOR structures
// before freeing up the resources.
...
// Free the array containing the error source information
SafeArrayUnaccessData(Array);
VariantClear(&Parameter);
// Free up resources
SysFreeString(ClassName);
SysFreeString(MethodName);
pOutParameters->Release();