在 WIA 设备上进行诊断

WIA 服务可以通过调用 IStiUSD::D iagnostic 方法测试设备的功能状态。 WIA 微型驱动程序应检查硬件的当前功能状态并报告结果。 在 WIA 设备的默认属性页 (Microsoft 提供的属性页) 按下“测试设备”按钮时,也会调用 IStiUSD::D iagnostic 方法。

以下示例演示 IStiUSD::D iagnostic 方法的 实现。

STDMETHODIMP CWIADevice::Diagnostic(LPSTI_DIAG pBuffer)
{
  //
  // If the caller did not pass in the correct parameters,
  // then fail the call with E_INVALIDARG.
  //

  if(!pBuffer){
     return E_INVALIDARG;
  }

  //
  // initialize response buffer
  //

  memset(&pBuffer->sErrorInfo,0,sizeof(pBuffer->sErrorInfo));

  pBuffer->sErrorInfo.dwGenericError = NOERROR;
  pBuffer->sErrorInfo.dwVendorError  = 0;

  HRESULT hr = S_OK;
  if(!TestMyDeviceFunctionalty()) {
    pBuffer->sErrorInfo.dwGenericError = E_FAIL; // win32 generic error code
    pBuffer->sErrorInfo.dwVendorError  = 1234;   // device specific vendor error code
  }
  return hr;
}