PWINBIO_ENROLL_CAPTURE_CALLBACK 函数由 Windows 生物识别框架调用,以从异步 WinBioEnrollCaptureWithCallback 函数返回结果。 客户端应用程序必须实现此函数。
              重要建议从 Windows 8 开始,不再使用 PWINBIO_ENROLL_CAPTURE_CALLBACK/WinBioEnrollCaptureWithCallback 组合。 请改为执行以下操作:
- 实现 PWINBIO_ASYNC_COMPLETION_CALLBACK 函数,以在操作完成时接收通知。
 - 调用 WinBioAsyncOpenSession 函数。 在 CallbackRoutine 参数中传递回调的地址。 在 NotificationMethod 参数中传递WINBIO_ASYNC_NOTIFY_CALLBACK。 检索异步会话句柄。
 - 使用异步会话句柄调用 WinBioEnrollCapture。 操作完成后,Windows 生物识别框架将使用结果分配和初始化 WINBIO_ASYNC_RESULT 结构,并使用指向结果结构的指针调用回调。
 - 从回调实现调用 WinBioFree ,以在使用完 WINBIO_ASYNC_RESULT 结构后释放它。
 
语法
PWINBIO_ENROLL_CAPTURE_CALLBACK PwinbioEnrollCaptureCallback;
VOID PwinbioEnrollCaptureCallback(
  [in, optional] PVOID EnrollCallbackContext,
  [in]           HRESULT OperationStatus,
  [in]           WINBIO_REJECT_DETAIL RejectDetail
)
{...}
参数
[in, optional] EnrollCallbackContext
指向由应用程序定义并传递给 WinBioEnrollCaptureWithCallback 函数的 EnrollCallback 参数的缓冲区的指针。 该缓冲区不会由框架或生物识别单元修改。 应用程序可以使用数据来帮助它确定要执行的操作或维护有关生物识别捕获的其他信息。
[in] OperationStatus
捕获操作返回的错误代码。
[in] RejectDetail
有关执行操作失败(如果有)的其他信息。 有关详细信息,请参阅“备注”。
返回值
无
备注
目前,Windows 生物识别框架仅支持指纹读取器。 因此,如果操作失败并在 WINBIO_REJECT_DETAIL 常量中返回其他信息,则它将是以下值之一:
- WINBIO_FP_TOO_HIGH
 - WINBIO_FP_TOO_LOW
 - WINBIO_FP_TOO_LEFT
 - WINBIO_FP_TOO_RIGHT
 - WINBIO_FP_TOO_FAST
 - WINBIO_FP_TOO_SLOW
 - WINBIO_FP_POOR_QUALITY
 - WINBIO_FP_TOO_SKEWED
 - WINBIO_FP_TOO_SHORT
 - WINBIO_FP_MERGE_FAILURE
 
示例
下面的代码示例通过调用 WinBioEnrollCaptureWithCallback 并将指针传递给自定义回调函数 EnrollCaptureCallback 来异步注册指纹。 链接到 Winbio.lib 静态库。
//------------------------------------------------------------------------
// EnrollSystemPoolWithCallback.cpp : console application entry point.
//
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <winbio.h>
//------------------------------------------------------------------------
// Forward declarations.
//
HRESULT EnrollSysPoolWithCallback(
                      BOOL bCancel,
                      BOOL bDiscard,
                      WINBIO_BIOMETRIC_SUBTYPE subFactor);
VOID CALLBACK EnrollCaptureCallback(
                      __in_opt PVOID EnrollCallbackContext,
                      __in HRESULT OperationStatus,
                      __in WINBIO_REJECT_DETAIL RejectDetail);
typedef struct _ENROLL_CALLBACK_CONTEXT {
    WINBIO_SESSION_HANDLE SessionHandle;
    WINBIO_UNIT_ID UnitId;
    WINBIO_BIOMETRIC_SUBTYPE SubFactor;
} ENROLL_CALLBACK_CONTEXT, *PENROLL_CALLBACK_CONTEXT;
//------------------------------------------------------------------------
int wmain()
{
    HRESULT hr = S_OK;
    hr = EnrollSysPoolWithCallback(
                      FALSE, 
                      FALSE, 
                      WINBIO_ANSI_381_POS_RH_INDEX_FINGER);
    return 0;
}
//------------------------------------------------------------------------
// The following function enrolls a user's fingerprint in the system pool.
// The function calls WinBioEnrollCaptureWithCallback and waits for the
// asynchronous enrollment process to be completed or canceled.
//
HRESULT EnrollSysPoolWithCallback(
                      BOOL bCancel,
                      BOOL bDiscard,
                      WINBIO_BIOMETRIC_SUBTYPE subFactor)
{
    // Declare variables
    HRESULT hr = S_OK;
    WINBIO_IDENTITY identity = {0};
    WINBIO_SESSION_HANDLE sessionHandle = NULL;
    WINBIO_UNIT_ID unitId = 0;
    BOOLEAN isNewTemplate = TRUE;
    ENROLL_CALLBACK_CONTEXT callbackContext = {0};
    // Connect to the system pool. 
    hr = WinBioOpenSession( 
            WINBIO_TYPE_FINGERPRINT,    // Service provider
            WINBIO_POOL_SYSTEM,         // Pool type
            WINBIO_FLAG_DEFAULT,        // Configuration and access
            NULL,                       // Array of biometric unit IDs
            0,                          // Count of biometric unit IDs
            NULL,                       // Database ID
            &sessionHandle              // [out] Session handle
            );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioEnumBiometricUnits failed. ");
        wprintf_s(L"hr = 0x%x\n", hr);
        goto e_Exit;
    }
    // Locate the sensor.
    wprintf_s(L"\n Swipe your finger to locate the sensor...\n");
    hr = WinBioLocateSensor( sessionHandle, &unitId);
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioLocateSensor failed. hr = 0x%x\n", hr);
        goto e_Exit;
    }
    // Begin the enrollment sequence. 
    hr = WinBioEnrollBegin(
            sessionHandle,      // Handle to open biometric session
            subFactor,          // Finger to create template for
            unitId              // Biometric unit ID
            );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioEnrollBegin failed. hr = 0x%x\n", hr);
        goto e_Exit;
    }
    // Set up the custom callback context structure.
    callbackContext.SessionHandle = sessionHandle;
    callbackContext.UnitId = unitId;
    callbackContext.SubFactor = subFactor;
    // Call WinBioEnrollCaptureWithCallback. This is an asynchronous
    // method that returns immediately.
    hr = WinBioEnrollCaptureWithCallback(
            sessionHandle,          // Handle to open biometric session
            EnrollCaptureCallback,  // Callback function
            &callbackContext        // Pointer to the custom context
            );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioEnrollCaptureWithCallback failed. ");
        wprintf_s(L"hr = 0x%x\n", hr);
        goto e_Exit;
    }
    wprintf_s(L"\n Swipe the sensor with the appropriate finger...\n");
    // Cancel the enrollment if the bCancel flag is set.
    if (bCancel)
    {
        wprintf_s(L"\n Starting CANCEL timer...\n");
        Sleep( 7000 );
        wprintf_s(L"\n Calling WinBioCancel\n");
        hr = WinBioCancel( sessionHandle );
        if (FAILED(hr))
        {
            wprintf_s(L"\n WinBioCancel failed. hr = 0x%x\n", hr);
            goto e_Exit;
        }
    }
    // Wait for the asynchronous enrollment process to complete
    // or be canceled.
    hr = WinBioWait( sessionHandle );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioWait failed. hr = 0x%x\n", hr);
    }
    // Discard the enrollment if the bDiscard flag is set.
    // Commit the enrollment if the flag is not set.
    if (bDiscard)
    {
        wprintf_s(L"\n Discarding enrollment...\n");
        hr = WinBioEnrollDiscard( sessionHandle );
        if (FAILED(hr))
        {
            wprintf_s(L"\n WinBioLocateSensor failed. ");
            wprintf_s(L"hr = 0x%x\n", hr);
        }
        goto e_Exit;    
    }
    else
    {
        wprintf_s(L"\n Committing enrollment...\n");
        hr = WinBioEnrollCommit( 
                sessionHandle,      // Handle to open biometric session
                &identity,          // WINBIO_IDENTITY object for the user
                &isNewTemplate);    // Is this a new template
        if (FAILED(hr))
        {
            wprintf_s(L"\n WinBioEnrollCommit failed. hr = 0x%x\n", hr);
            goto e_Exit;
        }
    }
e_Exit:
    if (sessionHandle != NULL)
    {
        WinBioCloseSession(sessionHandle);
        sessionHandle = NULL;
    }
    wprintf_s(L"\n Press any key to exit...");
    _getch();
    return hr;
}
//------------------------------------------------------------------------
// The following function is the callback for the Windows Biometric
// Framework WinBioEnrollCaptureWithCallback() function. 
//
VOID CALLBACK EnrollCaptureCallback(
    __in_opt PVOID EnrollCallbackContext,
    __in HRESULT OperationStatus,
    __in WINBIO_REJECT_DETAIL RejectDetail
    )
{
    // Declare variables.
    HRESULT hr = S_OK; 
    static SIZE_T swipeCount = 1;
    PENROLL_CALLBACK_CONTEXT callbackContext = 
        (PENROLL_CALLBACK_CONTEXT)EnrollCallbackContext;
    wprintf_s(L"\n EnrollCaptureCallback executing\n");
    wprintf_s(L"\n Sample %d captured", swipeCount++);
    // The capture was not acceptable or the enrollment operation
    // failed.
    if (FAILED(OperationStatus))
    {
        if (OperationStatus == WINBIO_E_BAD_CAPTURE)
        {
            wprintf_s(L"\n Bad capture; reason: %d\n", RejectDetail);
            wprintf_s(L"\n Swipe your finger to capture another sample.\n");
            // Try again.
            hr = WinBioEnrollCaptureWithCallback(
                    callbackContext->SessionHandle, // Open session handle
                    EnrollCaptureCallback,          // Callback function
                    EnrollCallbackContext           // Callback context
                    );
            if (FAILED(hr))
            {
                wprintf_s(L"WinBioEnrollCaptureWithCallback failed.");
                wprintf_s(L"hr = 0x%x\n", hr);
            }
        }
        else
        {
            wprintf_s(L"EnrollCaptureCallback failed.");
            wprintf_s(L"OperationStatus = 0x%x\n", OperationStatus);
        }
        goto e_Exit;
    }
    // The enrollment operation requires more fingerprint swipes.
    // This is normal and depends on your hardware. Typically, at least
    // three swipes are required.
    if (OperationStatus == WINBIO_I_MORE_DATA)
    {
        wprintf_s(L"\n More data required.");
        wprintf_s(L"\n Swipe your finger on the sensor again.");
        hr = WinBioEnrollCaptureWithCallback(
                callbackContext->SessionHandle,
                EnrollCaptureCallback,
                EnrollCallbackContext
                );
        if (FAILED(hr))
        {
            wprintf_s(L"WinBioEnrollCaptureWithCallback failed. ");
            wprintf_s(L"hr = 0x%x\n", hr);
        }
        goto e_Exit;
    }
    wprintf_s(L"\n Template completed\n");
e_Exit:
    return;
}
要求
| 要求 | 值 | 
|---|---|
| 最低受支持的客户端 | Windows 7 [仅限桌面应用] | 
| 最低受支持的服务器 | Windows Server 2008 R2 [仅限桌面应用] | 
| 目标平台 | Windows | 
| 标头 | winbio.h |