WinBioLockUnit 函数 (winbio.h)

锁定生物识别单元以供单个会话独占使用。 从 Windows 10 版本 1607 开始,此函数可用于移动映像。

语法

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

参数

[in] SessionHandle

标识打开的生物识别会话 的WINBIO_SESSION_HANDLE 值。 通过调用 WinBioOpenSession 打开同步会话句柄。 通过调用 WinBioAsyncOpenSession 打开异步会话句柄。

[in] UnitId

一个WINBIO_UNIT_ID值,该值指定要锁定的生物识别单元。

返回值

如果函数成功,则返回S_OK。 如果函数失败,它将返回指示错误的 HRESULT 值。 可能的值包括(但并不限于)下表中的项。 有关常见错误代码的列表,请参阅 常见 HRESULT 值

返回代码 说明
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指针。
若要防止内存泄漏,必须在使用完WINBIO_ASYNC_RESULT结构后调用 WinBioFree 以释放它。

示例

以下函数调用 WinBioLockUnit 以锁定生物识别单元,然后调用 WinBioIdentify 以识别用户。 链接到 Winbio.lib 静态库并包含以下头文件:

  • Windows.h
  • Stdio.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;
}


要求

   
最低受支持的客户端 Windows 7 [仅限桌面应用]
最低受支持的服务器 Windows Server 2008 R2 [仅限桌面应用]
目标平台 Windows
标头 winbio.h (包括 Winbio.h)
Library Winbio.lib
DLL Winbio.dll

另请参阅

WinBioUnlockUnit