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 值,以指出錯誤。

傳回碼 Description
E_POINTER
Pipeline 自變數不可為 NULL
E_OUTOFMEMORY
因為記憶體不足,所以無法完成作業。
WINBIO_E_INVALID_DEVICE_STATE
Pipeline 自變數所指向之WINBIO_PIPELINE結構的 SensorContext 成員不是 NULL

備註

在針對生物特徵辨識單位初始化引擎和儲存配接器之前,會呼叫此函式。 因此,此函式不得呼叫管線物件的 EngineInterfaceStorageInterface 成員所指向之WINBIO_ENGINE_INTERFACEWINBIO_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