共用方式為


WinBioLocateSensorWithCallback 函式(winbio.h)

非同步擷取使用者互動式選取的生物識別單元的 ID 號碼。 函式會立即回傳給呼叫者,在獨立執行緒處理,並透過呼叫應用程式定義的回調函式回報所選的生物特徵單元。

Important  

建議您從 Windows 8 開始,不再使用此函式來啟動非同步作業。 請改為執行下列動作:

  • 實作 PWINBIO_ASYNC_COMPLETION_CALLBACK 函式,以便在作業完成時接收通知。
  • 呼叫 WinBioAsyncOpenSession 函式。 在 CallbackRoutine 參數中傳遞回呼的位址。 在 NotificationMethod 參數中傳遞WINBIO_ASYNC_NOTIFY_CALLBACK。 擷取非同步工作階段控制碼。
  • 使用非同步會話的 handle 來呼叫 WinBioLocateSensor。 作業完成時,Windows 生物特徵辨識架構會使用結果配置和初始化 WINBIO_ASYNC_RESULT 結構,並使用結果結構的指標叫用回呼。
  • 從回呼實作呼叫 WinBioFree ,以在完成使用之後釋放 WINBIO_ASYNC_RESULT 結構。
 

語法

HRESULT WinBioLocateSensorWithCallback(
  [in]           WINBIO_SESSION_HANDLE          SessionHandle,
  [in]           PWINBIO_LOCATE_SENSOR_CALLBACK LocateCallback,
  [in, optional] PVOID                          LocateCallbackContext
);

參數

[in] SessionHandle

識別開啟生物特徵辨識工作階段的 WINBIO_SESSION_HANDLE 值。

[in] LocateCallback

當感測器定位成功或失敗時, WinBioLocateSensorWithCallback 函式將呼叫回調函式的位址。 您必須建立回呼。

[in, optional] LocateCallbackContext

應用程式定義的資料結構位址,該結構在其 LocateCallbackContext 參數中傳遞給回調函式。 此結構可以包含自訂回呼函式設計要處理的任何資料。

返回值

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

回傳碼 Description
E_HANDLE
工作階段控制碼無效。
E_POINTER
LocateCallback 參數所指定的位址不可能是 NULL。

備註

你可以在擁有多個感測器的系統上使用此功能,來判斷使用者偏好哪種感測器加入。 此函式不會回傳任何識別資訊。 它僅用於指示使用者感測器的選擇。

SessionHandle 參數指向系統感測器池,則回調函式將持續呼叫,直到應用程式取得視窗焦點且使用者提供生物特徵樣本。 你如何獲得專注,取決於你所撰寫的申請類型。 舉例來說,如果你正在建立一個圖形使用者體驗應用程式,你可以實作一個訊息處理器來捕捉WM_ACTIVATE、WM_SETFOCUS或其他適當的訊息。 如果你正在撰寫 CUI 應用程式,呼叫 GetConsoleWindow 取得主控台視窗的 handle,並將該 handle 傳給 SetForegroundWindow 函式,強制將主控台視窗移到前景並指派焦點。 如果你的應用程式是在分離程序中執行且沒有視窗,或是 Windows 服務,請使用 WinBioAcquireFocusWinBioReleaseFocus 手動控制焦點。

回呼常式必須具有下列簽章:


VOID CALLBACK LocateCallback(
__in_opt PVOID LocateCallbackContext,
__in HRESULT OperationStatus,
__in WINBIO_UNIT_ID UnitId
);

範例

以下函式呼叫 WinBioLocateSensorWithCallback 來定位生物特徵感測器。 WinBioLocateSensorWithCallback 是一個非同步函式,用來配置生物辨識子系統以定位感測器在另一執行緒上。 生物辨識子系統的輸出會傳送到一個名為 LocateSensorCallback 的自訂回調函式。 連結至 Winbio.lib 靜態程式庫,並包含下列標頭檔:

  • Windows.h
  • 標準.h
  • Conio.h
  • Winbio.h
HRESULT LocateSensorWithCallback(BOOL bCancel)
{
    HRESULT hr = S_OK;
    WINBIO_SESSION_HANDLE sessionHandle = NULL;
    WINBIO_UNIT_ID unitId = 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 WinBioOpenSession failed. hr = 0x%x\n", hr);
        goto e_Exit;
    }

    wprintf_s(L"\n Calling WinBioLocateSensorWithCallback.");
    hr = WinBioLocateSensorWithCallback(
                sessionHandle,          // Open biometric session
                LocateSensorCallback,   // Callback function
                NULL                    // Optional context
                );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioLocateSensorWithCallback failed.");
        wprintf_s(L"hr = 0x%x\n", hr);
        goto e_Exit;
    }
    wprintf_s(L"\n Swipe the sensor ...\n");

    // Cancel the identification 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 identification process to complete 
    // or be canceled.
    hr = WinBioWait( sessionHandle );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioWait failed. hr = 0x%x\n", hr);
    }

e_Exit:

    if (sessionHandle != NULL)
    {
       wprintf_s(L"\n Closing the session.\n");

        hr = WinBioCloseSession(sessionHandle);
        if (FAILED(hr))
        {
            wprintf_s(L"\n WinBioCloseSession failed. hr = 0x%x\n", hr);
        }
        sessionHandle = NULL;
    }

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

    return hr;
}

//------------------------------------------------------------------------
// The following function is the callback for 
// WinBioLocateSensorWithCallback. The function filters the response 
// from the biometric subsystem and writes a result to the console window.
// 
VOID CALLBACK LocateSensorCallback(
    __in_opt PVOID LocateCallbackContext,
    __in HRESULT OperationStatus,
    __in WINBIO_UNIT_ID UnitId
    )
{
    UNREFERENCED_PARAMETER(LocateCallbackContext);

    wprintf_s(L"\n LocateSensorCallback executing.");

    // A sensor could not be located.
    if (FAILED(OperationStatus))
    {
        wprintf_s(L"\n LocateSensorCallback failed.");
        wprintf_s(L"OperationStatus = 0x%x\n", OperationStatus);
    }
    // A sensor was located.
    else
    {
        wprintf_s(L"\n Selected unit ID: %d\n", UnitId);
    }
}


需求

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

另請參閱

WinBioLocateSensor