PIBIO_SENSOR_ATTACH_FN回调函数 (winbio_adapter.h)

在将传感器适配器添加到生物识别单元的处理管道时由 Windows 生物识别框架调用。 此函数的目的是执行后续生物识别操作所需的任何初始化。

语法

PIBIO_SENSOR_ATTACH_FN PibioSensorAttachFn;

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

参数

[in, out] Pipeline

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

返回值

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

返回代码 说明
E_POINTER
Pipeline 参数不能为 NULL
E_OUTOFMEMORY
由于内存不足,操作无法完成。
WINBIO_E_INVALID_DEVICE_STATE
Pipeline 参数指向的 WINBIO_PIPELINE 结构的 SensorContext 成员不是 NULL

注解

在为生物识别单元初始化引擎和存储适配器之前调用此函数。 因此,此函数不得调用WINBIO_ENGINE_INTERFACE引用的任何函数或管道对象的 EngineInterfaceStorageInterface 成员指向的WINBIO_STORAGE_INTERFACE结构。

由于 WINBIO_PIPELINE 结构的 SensorHandle 成员在调用此方法之前将包含有效的句柄,因此 SensorAdapterAttach 的实现在必要时可以使用句柄访问传感器设备。

实现此函数时,必须分配和管理适配器所需的任何资源,并将其附加到生物识别单元管道。 为此,请在堆上分配专用 WINBIO_SENSOR_CONTEXT 结构,对其进行初始化,并在管道对象的 SensorContext 成员中设置其地址。

如果在创建和初始化此函数使用的引擎适配器资源期间出错,则必须在返回之前执行任何必需的清理。

如果调用此函数时 SensorContext 字段不为 NULL ,则之前调用 SensorAdapterDetach 未正确重置管道,必须返回 WINBIO_E_INVALID_DEVICE_STATE 以通知 Windows 生物识别框架出现问题。

示例

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

//////////////////////////////////////////////////////////////////////////////////////////
//
// SensorAdapterAttach
//
// Purpose:
//      Performs any initialization required for later biometric operations.
//
// Parameters:
//      Pipeline -  Pointer to a WINBIO_PIPELINE structure associated with 
//                  the biometric unit performing the operation.
//
static HRESULT
WINAPI
SensorAdapterAttach(
    __inout PWINBIO_PIPELINE Pipeline
    )
{
    HRESULT hr = S_OK;
    PWINBIO_SENSOR_CONTEXT newContext = NULL;

    // Verify that the Pipeline parameter is not NULL.
    if (!ARGUMENT_PRESENT(Pipeline))
    {
        hr = E_POINTER;
        goto cleanup;
    }

    // Validate the current sensor state.
    if (Pipeline->SensorContext != NULL)
    {
        hr = WINBIO_E_INVALID_DEVICE_STATE;
        goto cleanup;
    }

    // Use a custom function (_AdapterAlloc) to allocate memory for the 
    // sensor adapter context.
    newContext = (PWINBIO_SENSOR_CONTEXT)_AdapterAlloc(sizeof(WINBIO_SENSOR_CONTEXT));
    if (newContext == NULL)
    {
        hr = E_OUTOFMEMORY;
        goto cleanup;
    }

    // Create a manual reset event to monitor overlapped I/O.
    newContext->Overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (newContext->Overlapped.hEvent == NULL)
    {
        hr = E_OUTOFMEMORY;
        goto cleanup;
    }

    // Initialize any required context fields. This example assumes that your
    // sensor context points to a capture buffer and an attributes buffer.
    newContext->CaptureBuffer = NULL;
    newContext->CaptureBufferSize = 0;

    newContext->AttributesBuffer = NULL;
    newContext->AttributesBufferSize = sizeof (WINBIO_SENSOR_ATTRIBUTES);

    // Transfer ownership of the new sensor context structure to the 
    // pipeline.
    Pipeline->SensorContext = newContext;
    newContext = NULL;

cleanup:

    if (FAILED(hr) && newContext != NULL)
    {
        CloseHandle( newContext->Overlapped.hEvent;
        _AdapterRelease( newContext );
        newContext = NULL;
    }
    return hr;
}

要求

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

另请参阅

EngineAdapterAttach

插件函数

SensorAdapterDetach

StorageAdapterAttach

WINBIO_PIPELINE