共用方式為


WinBioEnrollCapture 函數(winbio.h)

擷取生物特徵樣本並加入範本。 從 Windows 10 版本 1607 開始,此功能可用於行動映像檔。

語法

HRESULT WinBioEnrollCapture(
  [in]            WINBIO_SESSION_HANDLE SessionHandle,
  [out, optional] WINBIO_REJECT_DETAIL  *RejectDetail
);

參數

[in] SessionHandle

識別開啟生物特徵辨識工作階段的 WINBIO_SESSION_HANDLE 值。 呼叫 WinBioOpenSession 開啟同步會話的 handle 。 透過呼叫 WinBioAsyncOpenSession 開啟非同步會話句柄。

[out, optional] RejectDetail

指向 ULONG 值的指標,其中包含額外資訊:生物特徵樣本未被捕捉。 若捕獲成功,該參數為零。 下列值會針對指紋擷取定義:

  • 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

返回值

如果函式成功,則會傳回S_OK。 如果函式失敗,它會傳回指出錯誤的 HRESULT 值。 可能的值包括但不限於下表中的值。 如需常見錯誤碼的清單,請參閱 常見的 HRESULT 值

回傳碼 Description
E_ACCESSDENIED
來電帳號不允許進行註冊。
E_HANDLE
工作階段控制碼無效。
E_POINTER
RejectDetail 參數指定的指標不能是 NULL。
WINBIO_E_BAD_CAPTURE
該樣本無法被捕捉。 請使用 RejectDetail 值以獲得更多資訊。
WINBIO_E_LOCK_VIOLATION
生物辨識裝置正在使用且已鎖定。
WINBIO_I_MORE_DATA
匹配引擎需要一個或多個額外的樣本來產生可靠的範本。 你應該更新使用者提交更多樣本的指示,並再次致電 WinBioEnrollCapture

備註

任何透過系統池中生物辨識單元註冊的應用程式,在呼叫 WinBioEnrollBegin 時必須設定視窗焦點。 若未達成,呼叫會阻塞,直到應用程式取得視窗焦點且使用者提供生物特徵樣本。 因此,我們建議您的應用程式在獲得焦點之前,不要呼叫 WinBioEnrollBegin 。 你如何獲得專注,取決於你所撰寫的申請類型。 舉例來說,如果你正在建立一個圖形使用者體驗應用程式,你可以實作一個訊息處理器來捕捉WM_ACTIVATE、WM_SETFOCUS或其他適當的訊息。 如果你正在撰寫 CUI 應用程式,呼叫 GetConsoleWindow 取得主控台視窗的 handle,並將該 handle 傳給 SetForegroundWindow 函式,強制將主控台視窗移到前景並指派焦點。 如果你的應用程式是在分離程序中執行且沒有視窗,或是 Windows 服務,請使用 WinBioAcquireFocusWinBioReleaseFocus 手動控制焦點。

若要同步使用 WinBioEnrollCapture ,請呼叫由 WinBioOpenSession 建立的會話句柄。 該函式會阻塞,直到操作完成或遇到錯誤。

若要非同步使用 WinBioEnrollCapture ,請呼叫該函式,並透過呼叫 WinBioAsyncOpenSession 建立的會話句柄。 該框架分配一個 WINBIO_ASYNC_RESULT 結構,並用它來回傳有關操作成功或失敗的資訊。 若操作失敗,框架會以巢狀 EnrollCapture 結構回傳WINBIO_REJECT_DETAIL資訊。 WINBIO_ASYNC_RESULT結構會根據您在 WinBioAsyncOpenSession 函式的 NotificationMethod 參數中設定的值,回傳到應用程式回撥或應用程式訊息佇列:

  • 如果你選擇透過回撥接收完成通知,必須實作 一個PWINBIO_ASYNC_COMPLETION_CALLBACK 函式,並將 NotificationMethod 參數設為 WINBIO_ASYNC_NOTIFY_CALLBACK
  • 如果你選擇透過應用程式訊息隊列接收完成通知,必須將 NotificationMethod 參數設為 WINBIO_ASYNC_NOTIFY_MESSAGE。 框架回傳一個指向視窗訊息 LPARAM 欄位的 WINBIO_ASYNC_RESULT指標。
為防止記憶體洩漏,使用結束後,必須從回調實作中呼叫 WinBioFree ,釋放 WINBIO_ASYNC_RESULT 結構。

Windows 7: 你可以透過 WinBioEnrollCaptureWithCallback 函式非同步執行此操作。 函式會驗證輸入參數並立即回傳。 若輸入參數無效,函式會回傳錯誤碼。 否則,框架會在另一個執行緒開始操作。 當非同步操作完成或遇到錯誤時,框架會將結果傳送給應用程式實作的 PWINBIO_ENROLL_CAPTURE_CALLBACK 函式。

範例

以下函式透過呼叫 WinBioEnrollCapture 將生物特徵範本註冊到系統池中。 連結至 Winbio.lib 靜態程式庫,並包含下列標頭檔:

  • Windows.h
  • 標準.h
  • Conio.h
  • Winbio.h
HRESULT EnrollSysPool(
                      BOOL discardEnrollment, 
                      WINBIO_BIOMETRIC_SUBTYPE subFactor)
{
    HRESULT hr = S_OK;
    WINBIO_IDENTITY identity = {0};
    WINBIO_SESSION_HANDLE sessionHandle = NULL;
    WINBIO_UNIT_ID unitId = 0;
    WINBIO_REJECT_DETAIL rejectDetail = 0;
    BOOLEAN isNewTemplate = TRUE;

    // 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 WinBioOpenSession failed. ");
        wprintf_s(L"hr = 0x%x\n", hr);
        goto e_Exit;
    }

    // Locate a sensor.
    wprintf_s(L"\n Swipe your finger on 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. 
    wprintf_s(L"\n Starting enrollment sequence...\n");
    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;
    }

    // Capture enrollment information by swiping the sensor with
    // the finger identified by the subFactor argument in the 
    // WinBioEnrollBegin function.
    for (int swipeCount = 1;; ++swipeCount)
    {
        wprintf_s(L"\n Swipe the sensor to capture %s sample.",
                 (swipeCount == 1)?L"the first":L"another");

        hr = WinBioEnrollCapture(
                sessionHandle,  // Handle to open biometric session
                &rejectDetail   // [out] Failure information
                );

        wprintf_s(L"\n Sample %d captured from unit number %d.", 
                  swipeCount, 
                  unitId);

        if (hr == WINBIO_I_MORE_DATA)
        {
            wprintf_s(L"\n    More data required.\n");
            continue;
        }
        if (FAILED(hr))
        {
            if (hr == WINBIO_E_BAD_CAPTURE)
            {
                wprintf_s(L"\n  Error: Bad capture; reason: %d", 
                          rejectDetail);
                continue;
            }
            else
            {
                wprintf_s(L"\n WinBioEnrollCapture failed. hr = 0x%x", hr);
                goto e_Exit;
            }
        }
        else
        {
            wprintf_s(L"\n    Template completed.\n");
            break;
        }
    }

    // Discard the enrollment if the appropriate flag is set.
    // Commit the enrollment if it is not discarded.
    if (discardEnrollment == TRUE)
    {
        wprintf_s(L"\n Discarding enrollment...\n\n");
        hr = WinBioEnrollDiscard( sessionHandle );
        if (FAILED(hr))
        {
            wprintf_s(L"\n WinBioLocateSensor failed. 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" Press any key to continue...");
    _getch();

    return hr;
}


需求

Requirement 價值觀
最低支援的用戶端 Windows 7 [僅限桌面應用程式]
支援的最低伺服器 Windows Server 2008 R2 [僅限傳統型應用程式]
目標平臺 窗戶
Header winbio.h(包括Winbio.h)
Library Winbio.lib 網站
DLL Winbio.dll

另請參閱

WinBioAcquireFocus(WinBioAcquireFocus)

WinBio註冊開始

WinBio註冊CaptureWithCallback(回撥)

WinBioEnrollCommit

WinBioEnrollDiscard(WinBioEnrollDiscard)

WinBioReleaseFocus(WinBioReleaseFocus)