PIBIO_SENSOR_DETACH_FN回调函数 (winbio_adapter.h)

在从生物识别单元的处理管道中删除传感器适配器之前,由 Windows 生物识别框架调用。 此函数的目的是释放附加到管道的特定适配器资源。

语法

PIBIO_SENSOR_DETACH_FN PibioSensorDetachFn;

HRESULT PibioSensorDetachFn(
  [in, out] PWINBIO_PIPELINE Pipeline
)
{...}

参数

[in, out] Pipeline

指向与执行操作的生物识别单元关联的 WINBIO_PIPELINE 结构的指针。

返回值

如果函数成功,则返回S_OK。 如果函数失败,它必须返回以下 HRESULT 值之一来指示错误。

返回代码 说明
E_POINTER
Pipeline 参数不能为 NULL
WINBIO_E_INVALID_DEVICE_STATE
WINBIO_PIPELINE 结构的 SensorContext 字段不能为 NULL

注解

若要防止内存泄漏,SensorAdapterDetach 函数的实现必须释放管道的 SensorContext 成员指向的专用WINBIO_SENSOR_CONTEXT结构,以及附加到传感器上下文的任何其他资源。

如果调用此函数时管道对象中的 SensorContext 字段为 NULL ,则表示管道未正确初始化,必须返回 WINBIO_E_INVALID_DEVICE_STATE 以通知 Windows 生物识别框架该问题。

在返回S_OK之前,此函数必须将 WINBIO_PIPELINE 结构的 SensorContext 字段设置为 NULL

由于此函数是在从管道中删除存储和引擎适配器后调用的,因此此函数的实现不得调用管道对象的 EngineInterfaceStorageInterface 成员指向的WINBIO_ENGINE_INTERFACEWINBIO_STORAGE_INTERFACE结构所引用的任何函数。

因为即使调用 SensorAdapterDetach 之后,WINBIO_PIPELINE结构的 SensorHandle 成员也会包含有效的句柄,因此如有必要,可以使用句柄访问传感器设备。 此函数不应关闭传感器句柄。 Windows 生物识别框架将在 SensorAdapterDetach 返回后执行此操作。

示例

以下伪代码演示了此函数的一种可能实现。 该示例不编译。 必须根据自己的目的调整它。

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

要求

要求
最低受支持的客户端 Windows 7 [仅限桌面应用]
最低受支持的服务器 Windows Server 2008 R2 [仅限桌面应用]
目标平台 Windows
标头 winbio_adapter.h (包括 Winbio_adapter.h)

另请参阅

插件函数

SensorAdapterAttach

WINBIO_PIPELINE