Kommentar
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Ett användarlägesprogram kan hämta information om en viss felkälla som stöds av maskinvaruplattformen genom att anropa metoden WHEAErrorSourceMethods::GetErrorSourceInfoRtn . Den här metoden returnerar en WHEA_ERROR_SOURCE_DESCRIPTOR struktur som beskriver den angivna felkällan.
Följande kodexempel visar hur du hämtar felkällans information för en viss felkälla.
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();