共用方式為


WinBioLockUnit 函式 (winbio.h)

鎖定生物辨識單元,僅限單一會話使用。 從 Windows 10 版本 1607 開始,此功能可用於行動映像檔。

語法

HRESULT WinBioLockUnit(
  [in] WINBIO_SESSION_HANDLE SessionHandle,
  [in] WINBIO_UNIT_ID        UnitId
);

參數

[in] SessionHandle

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

[in] UnitId

一個 WINBIO_UNIT_ID 值,指定要鎖定的生物特徵單位。

返回值

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

回傳碼 Description
E_HANDLE
工作階段控制碼無效。
E_INVALIDARG
UnitId 參數不可能包含零。
WINBIO_E_ENROLLMENT_IN_PROGRESS
由於指定的生物特徵單位目前正用於註冊交易(僅限系統池),該操作無法完成。
WINBIO_E_LOCK_VIOLATION
生物特徵單元無法被鎖定,因為指定的會話已經有其他單元被鎖定。

備註

若指定的生物特徵單元被其他會話鎖定, WinBioLockUnit 會阻擋呼叫執行緒,直到擁有該生物特徵單元的會話解除鎖定。

呼叫 WinBioUnlockUnit 函式來取消任何待處理的鎖請求,並解除該會話中所有持有的鎖。

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

若要非同步使用 WinBioLockUnit ,請呼叫該函式,並透過呼叫 WinBioAsyncOpenSession 建立會話句柄。 該框架分配一個 WINBIO_ASYNC_RESULT 結構,並用它來回傳有關操作成功或失敗的資訊。 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 結構。

範例

以下函式呼叫 WinBioLockUnit 鎖定生物辨識單元,再呼叫 WinBioIdentify 以識別使用者。 連結至 Winbio.lib 靜態程式庫,並包含下列標頭檔:

  • Windows.h
  • 標準.h
  • Conio.h
  • Winbio.h
HRESULT LockUnlock( )
{
    // Declare variables.
    HRESULT hr = S_OK;
    WINBIO_IDENTITY identity = {0};
    WINBIO_SESSION_HANDLE sessionHandle = NULL;
    WINBIO_UNIT_ID unitId = 0;
    WINBIO_REJECT_DETAIL rejectDetail = 0;
    WINBIO_BIOMETRIC_SUBTYPE subFactor = WINBIO_SUBTYPE_NO_INFORMATION;
    BOOL lockAcquired = FALSE;

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

    // Lock the session. The Biometric unit ID (1) is hard coded in
    // this example.
    hr = WinBioLockUnit( sessionHandle, 1 );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioLockUnit failed. hr = 0x%x\n", hr);
        goto e_Exit;
    }
    wprintf_s(L"\n Biometric unit #1 is locked.\n");
    lockAcquired = TRUE;


    // Locate the biometric sensor and retrieve a WINBIO_IDENTITY object.
    // You must swipe your finger on the sensor.
    wprintf_s(L"\n Calling WinBioIdentify - Swipe finger on sensor...\n");
    hr = WinBioIdentify( 
            sessionHandle, 
            &unitId, 
            &identity, 
            &subFactor, 
            &rejectDetail
            );
    wprintf_s(L"\n Swipe processed - Unit ID: %d\n", unitId);
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioIdentify failed. hr = 0x%x\n", hr);
        goto e_Exit;
    }


e_Exit:

    // Unlock the biometric unit if it is locked.
    if (lockAcquired == TRUE)
    {
        hr = WinBioUnlockUnit( sessionHandle, 1 );
        if (FAILED(hr))
        {
            wprintf_s(L"\n WinBioUnlockUnit failed. hr = 0x%x\n", hr);
        }
        wprintf_s(L"\n Biometric unit #1 is unlocked.\n");
        lockAcquired = FALSE;
    }

    if (sessionHandle != NULL)
    {
        WinBioCloseSession(sessionHandle);
        sessionHandle = NULL;
    }

    wprintf_s(L"\n Press any key to exit...");
    _getch();

    return hr;
}


需求

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

另請參閱

WinBio解鎖單元