Bagikan melalui


Fungsi WinBioEnrollCaptureWithCallback (winbio.h)

Secara asinkron menangkap sampel biometrik dan menambahkannya ke templat. Fungsi ini segera kembali ke pemanggil, melakukan pendaftaran pada utas terpisah, dan memanggil ke fungsi panggilan balik yang ditentukan aplikasi untuk memperbarui status operasi.

Penting  

Kami menyarankan agar, dimulai dengan Windows 8, Anda tidak lagi menggunakan fungsi ini untuk memulai operasi asinkron. Sebagai gantinya, lakukan hal berikut:

  • Terapkan fungsi PWINBIO_ASYNC_COMPLETION_CALLBACK untuk menerima pemberitahuan ketika operasi selesai.
  • Panggil fungsi WinBioAsyncOpenSession . Teruskan alamat panggilan balik Anda di parameter CallbackRoutine . Teruskan WINBIO_ASYNC_NOTIFY_CALLBACK dalam parameter NotificationMethod . Ambil handel sesi asinkron.
  • Gunakan handel sesi asinkron untuk memanggil WinBioEnrollCapture. Ketika operasi selesai, Windows Biometric Framework akan mengalokasikan dan menginisialisasi struktur WINBIO_ASYNC_RESULT dengan hasil dan memanggil panggilan balik Anda dengan penunjuk ke struktur hasil.
  • Panggil WinBioFree dari implementasi panggilan balik Anda untuk merilis struktur WINBIO_ASYNC_RESULT setelah Anda selesai menggunakannya.
 

Sintaks

HRESULT WinBioEnrollCaptureWithCallback(
  [in]           WINBIO_SESSION_HANDLE           SessionHandle,
  [in]           PWINBIO_ENROLL_CAPTURE_CALLBACK EnrollCallback,
  [in, optional] PVOID                           EnrollCallbackContext
);

Parameter

[in] SessionHandle

Nilai WINBIO_SESSION_HANDLE yang mengidentifikasi sesi biometrik terbuka.

[in] EnrollCallback

Alamat fungsi panggilan balik yang akan dipanggil oleh fungsi WinBioEnrollCaptureWithCallback ketika operasi penangkapan berhasil atau gagal. Anda harus membuat panggilan balik.

[in, optional] EnrollCallbackContext

Penunjuk ke struktur opsional yang ditentukan aplikasi yang diteruskan ke parameter EnrollCallbackContext dari fungsi panggilan balik. Struktur ini dapat berisi data apa pun yang dirancang untuk ditangani oleh fungsi panggilan balik kustom.

Mengembalikan nilai

Jika fungsi berhasil, fungsi akan mengembalikan S_OK. Jika fungsi gagal, fungsi mengembalikan nilai HRESULT yang menunjukkan kesalahan. Nilai yang mungkin termasuk, tetapi tidak terbatas pada, yang ada dalam tabel berikut. Untuk daftar kode kesalahan umum, lihat Nilai HRESULT Umum.

Menampilkan kode Deskripsi
E_ACCESSDENIED
Akun panggilan tidak diizinkan untuk melakukan pendaftaran.
E_HANDLE
Handel sesi tidak valid.
E_POINTER
Penunjuk yang ditentukan oleh parameter EnrollCallback tidak boleh NULL.

Keterangan

Jika parameter SessionHandle mengacu pada kumpulan sensor sistem, fungsi panggilan balik tidak akan dipanggil sampai aplikasi memperoleh fokus jendela dan pengguna telah memberikan sampel biometrik. Cara Anda memperoleh fokus tergantung pada jenis aplikasi yang Anda tulis. Misalnya, jika Anda membuat aplikasi GUI, Anda dapat mengimplementasikan penangan pesan yang menangkap WM_ACTIVATE, WM_SETFOCUS, atau pesan lain yang sesuai. Jika Anda menulis aplikasi CUI, panggil GetConsoleWindow untuk mengambil handel ke jendela konsol dan meneruskan handel tersebut ke fungsi SetForegroundWindow untuk memaksa jendela konsol ke latar depan dan menetapkan fokusnya. Jika aplikasi Anda berjalan dalam proses yang dilepas dan tidak memiliki jendela atau merupakan layanan Windows, gunakan WinBioAcquireFocus dan WinBioReleaseFocus untuk mengontrol fokus secara manual.

Contoh

Contoh kode berikut mendaftarkan sidik jari secara asinkron dengan memanggil WinBioEnrollCaptureWithCallback dan meneruskan pointer ke fungsi panggilan balik kustom. Fungsi panggilan balik, EnrollCaptureCallback, juga ditampilkan. Tautkan ke pustaka statis 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;
}


Persyaratan

Persyaratan Nilai
Klien minimum yang didukung Windows 7 [hanya aplikasi desktop]
Server minimum yang didukung Windows Server 2008 R2 [hanya aplikasi desktop]
Target Platform Windows
Header winbio.h (termasuk Winbio.h)
Pustaka Winbio.lib
DLL Winbio.dll

Lihat juga

WinBioAcquireFocus

WinBioEnrollBegin

WinBioEnrollCapture

WinBioEnrollCommit

WinBioEnrollDiscard

WinBioReleaseFocus