Win32 API 日本語リファレンス
ホーム › Devices.BiometricFramework › PIBIO_SENSOR_DETACH_FN

PIBIO_SENSOR_DETACH_FN

コールバック

シグネチャ

HRESULT PIBIO_SENSOR_DETACH_FN(
    WINBIO_PIPELINE* Pipeline
);

パラメーター

フィールド型説明
PipelineWINBIO_PIPELINE*操作を実行するバイオメトリックユニットに関連付けられた WINBIO_PIPELINE 構造体へのポインター。

公式ドキュメント

Windows Biometric Framework は、センサーアダプターがバイオメトリックユニットの処理パイプラインから削除される直前に、この関数を呼び出します。この関数の目的は、パイプラインに関連付けられているアダプター固有のリソースを解放することです。

戻り値

関数が成功した場合は S_OK を返します。関数が失敗した場合は、エラーを示すために次の HRESULT 値のいずれかを返す必要があります。

戻り値 説明
E_POINTER
Pipeline パラメーターを NULL にすることはできません。
WINBIO_E_INVALID_DEVICE_STATE
WINBIO_PIPELINE 構造体の SensorContext フィールドを NULL にすることはできません。

解説(Remarks)

メモリリークを防ぐため、SensorAdapterDetach 関数の実装では、パイプラインの SensorContext メンバーが指すプライベートな WINBIO_SENSOR_CONTEXT 構造体と、センサーコンテキストに関連付けられているその他のリソースを解放する必要があります。

この関数が呼び出された時点でパイプラインオブジェクトの SensorContext フィールドが NULL である場合、パイプラインは正しく初期化されていません。その場合は WINBIO_E_INVALID_DEVICE_STATE を返して、問題を Windows Biometric Framework に通知する必要があります。

この関数は、S_OK を返す前に WINBIO_PIPELINE 構造体の SensorContext フィールドを NULL に設定する必要があります。

この関数は、ストレージアダプターとエンジンアダプターがパイプラインから削除された後に呼び出されます。そのため、この関数の実装では、パイプラインオブジェクトの EngineInterface メンバーおよび StorageInterface メンバーが指す WINBIO_ENGINE_INTERFACE 構造体や WINBIO_STORAGE_INTERFACE 構造体から参照される関数を呼び出してはなりません。

WINBIO_PIPELINE 構造体の SensorHandle メンバーは SensorAdapterDetach の呼び出し後も有効なハンドルを保持するため、必要であればそのハンドルを使用してセンサーデバイスにアクセスできます。この関数でセンサーハンドルを閉じないでください。SensorAdapterDetach が戻った後に、Windows Biometric Framework がハンドルを閉じます。

例

次の擬似コードは、この関数の実装例の 1 つを示しています。この例はコンパイルできません。目的に合わせて適宜変更してください。

//////////////////////////////////////////////////////////////////////////////////////////
//
// SensorAdapterDetach
//
// Purpose:
//      Cancels all pending sensor operations.
//      
// Parameters:
//      Pipeline -  Pointer to a WINBIO_PIPELINE structure associated with 
//                  the biometric unit.
//
static HRESULT
WINAPI
SensorAdapterDetach(
    __inout PWINBIO_PIPELINE Pipeline
    )
{
    PWINBIO_SENSOR_CONTEXT sensorContext = NULL;

    // Verify that the Pipeline parameter is not NULL.
    if (!ARGUMENT_PRESENT(Pipeline))
    {
        hr = E_POINTER;
        goto cleanup;
    }
 
    // Validate the current state of the sensor.
    if (Pipeline->SensorContext == NULL)
    {
        return WINBIO_E_INVALID_DEVICE_STATE;
    }

    // Cancel any pending I/O to the device.
    SensorAdapterCancel(Pipeline);

    // Take ownership of the sensor context from the pipeline.
    sensorContext = (PWINBIO_SENSOR_CONTEXT)Pipeline->SensorContext;
    Pipeline->SensorContext = NULL;

    // Release any structures that remain attached to the context block. 
    // The following example assumes that your sensor adapter context 
    // contains pointers to a capture buffer and an attributes buffer.
    if (sensorContext->CaptureBuffer != NULL)
    {
        // Zero the capture buffer.
        SecureZeroMemory(
            sensorContext->CaptureBuffer,
            sensorContext->CaptureBufferSize);

        // Release the capture buffer.
        _AdapterRelease(sensorContext->CaptureBuffer);
        sensorContext->CaptureBuffer = NULL;
        sensorContext->CaptureBufferSize = 0;
    }

    if (sensorContext->AttributesBuffer != NULL)
    {
        // Zero the attributes buffer.
        SecureZeroMemory(
            sensorContext->AttributesBuffer,
            sensorContext->AttributesBufferSize);

        // Release the attributes buffer.
        _AdapterRelease(sensorContext->AttributesBuffer);
        sensorContext->AttributesBuffer = NULL;
        sensorContext->AttributesBufferSize = 0;
    }

    // Close the overlapped I/O event handle.
    CloseHandle(sensorContext->Overlapped.hEvent);

    // Release the context structure.
    _AdapterRelease(sensorContext);
    sensorContext = NULL;
   
    return S_OK;
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)