次の方法で共有


エラー ソース情報の設定

ユーザー モード アプリケーションは、WHEAErrorSourceMethods::SetErrorSourceInfoRtn メソッドを呼び出すことによって、ハードウェア プラットフォームでサポートされている特定のエラー ソースの情報を設定できます。 このような状況では、アプリケーションは、指定されたエラー ソースに設定する情報を記述する WHEA_ERROR_SOURCE_DESCRIPTOR 構造を提供します。

次のコード例は、特定のエラー ソースのエラー ソース情報を設定する方法を示しています。

IWbemServices *pIWbemServices;
WHEA_ERROR_SOURCE_DESCRIPTOR ErrorSourceInfo;
BSTR ClassName;
BSTR MethodName;
HRESULT Result;
IWbemClassObject *pClass;
IWbemClassObject *pInParametersClass;
IWbemClassObject *pInParameters;
IWbemClassObject *pOutParameters;
VARIANT Parameter;
SAFEARRAY *Array;
PVOID ArrayData;
ULONG Status;

// 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 ErrorSourceInfo
// contains the error source information to be set.

// Note that the SetErrorSourceInfoRtn method determines
// the identifier of the error source for which the
// information is being set from the ErrorSourceId
// member of the WHEA_ERROR_SOURCE_DESCRIPTOR structure.

// Specify the class and method to execute
ClassName = SysAllocString(L"WHEAErrorSourceMethods");
MethodName = SysAllocString(L"SetErrorSourceInfoRtn");

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

// Create a safe array for the error source information
Array =
  SafeArrayCreateVector(
    VT_UI1,
    0,
    sizeof(WHEA_ERROR_SOURCE_DESCRIPTOR)
    );

// Get access to the data buffer
Result =
  SafeArrayAccessData(
    Array,
    &ArrayData
    );

// Copy the error source information
*(PWHEA_ERROR_SOURCE_DESCRIPTOR)ArrayData =
  ErrorSourceInfo;

// Release access to the data buffer
SafeArrayUnaccessData(Array);

// Set the ErrorSourceInfo parameter
Parameter.vt = VT_ARRAY | VT_UI1;
Parameter.parray = Array;
Result =
  pInParameters->Put(
    L"ErrorSourceInfo",
    0,
    &Parameter,
    0
    );
VariantClear(&Parameter);

// Set the Length parameter
Parameter.vt = VT_UI4;
Parameter.ulVal = sizeof(WHEA_ERROR_SOURCE_DESCRIPTOR);
Result =
  pInParameters->Put(
    L"Length",
    0,
    &Parameter,
    0
    );
VariantClear(&Parameter);

// Call the SetErrorSourceInfoRtn 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);

// Free up resources
SysFreeString(ClassName);
SysFreeString(MethodName);
pInParameters->Release();
pInParametersClass->Release();
pClass->Release();
pOutParameters->Release();

通常、アプリケーションは、エラー ソースの構成を変更するときにエラー ソースの情報を設定します。 アプリケーションは、次の手順を実行することにより、エラー ソースの構成を変更することができます。

  1. 特定のエラー ソースを記述する WHEA_ERROR_SOURCE_DESCRIPTOR 構造を取得します。

    システム内のすべてのエラー ソースに関する情報を取得する方法について詳しくは、「すべてのエラー ソースのエラー ソース情報の取得」をご覧ください。

    システム内の特定のエラー ソースに関する情報を取得する方法について詳しくは、「特定のエラー ソースのエラー ソース情報の取得」をご覧ください。

  2. エラー ソースの構成を変更するには、WHEA_ERROR_SOURCE_DESCRIPTOR 構造の内容を変更します。

  3. WHEAErrorSourceMethods::SetErrorSourceInfoRtn メソッドを呼び出すことにより、エラー ソースのエラー ソース情報を設定します。

エラー ソースの構成に加えられた変更は、システムが再起動されるまで有効になりません。