Win32 API 日本語リファレンス
ホーム › Devices.BiometricFramework › WinBioEnrollCapture

WinBioEnrollCapture

関数
登録のため生体サンプルを採取する。
DLLwinbio.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

// winbio.dll
#include <windows.h>

HRESULT WinBioEnrollCapture(
    DWORD SessionHandle,
    DWORD* RejectDetail   // optional
);

パラメーター

名前型方向説明
SessionHandleDWORDinオープンされているバイオメトリックセッションを識別する WINBIO_SESSION_HANDLE 値です。同期セッションハンドルは WinBioOpenSession を呼び出して開きます。非同期セッションハンドルは WinBioAsyncOpenSession を呼び出して開きます。
RejectDetailDWORD*outoptional

バイオメトリックサンプルのキャプチャに失敗した理由に関する追加情報が格納される ULONG 値へのポインターです。キャプチャに成功した場合、このパラメーターには 0 が設定されます。指紋のキャプチャでは次の値が定義されています。

  • 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

戻り値の型: HRESULT

公式ドキュメント

バイオメトリックサンプルをキャプチャし、テンプレートに追加します。Windows 10 ビルド 1607 以降、この関数はモバイルイメージで使用できます。

戻り値

関数が成功した場合は S_OK を返します。関数が失敗した場合は、エラーを示す HRESULT 値を返します。戻り値には次の表に示すものが含まれますが、これらに限定されません。一般的なエラーコードの一覧については、Common HRESULT Values を参照してください。

戻り値 説明
E_ACCESSDENIED
呼び出し元のアカウントには登録を実行する権限がありません。
E_HANDLE
セッションハンドルが無効です。
E_POINTER
RejectDetail パラメーターで指定するポインターに NULL を指定することはできません。
WINBIO_E_BAD_CAPTURE
サンプルをキャプチャできませんでした。詳細については RejectDetail の値を参照してください。
WINBIO_E_LOCK_VIOLATION
バイオメトリックユニットは使用中でロックされています。
WINBIO_I_MORE_DATA
照合エンジンが信頼できるテンプレートを生成するには、1 つ以上の追加サンプルが必要です。さらにサンプルを提供するようユーザーへの指示を更新し、WinBioEnrollCapture を再度呼び出してください。

解説(Remarks)

システムプール内のバイオメトリックユニットを使用して登録を行うアプリケーションは、WinBioEnrollBegin を呼び出す時点でウィンドウフォーカスを持っている必要があります。そうでない場合、その呼び出しは、アプリケーションがウィンドウフォーカスを取得し、ユーザーがバイオメトリックサンプルを提供するまでブロックされます。したがって、フォーカスを取得するまで WinBioEnrollBegin を呼び出さないことをお勧めします。フォーカスを取得する方法は、作成するアプリケーションの種類によって異なります。たとえば、GUI アプリケーションを作成する場合は、WM_ACTIVATE、WM_SETFOCUS、またはその他の適切なメッセージを捕捉するメッセージハンドラーを実装できます。CUI アプリケーションを作成する場合は、GetConsoleWindow を呼び出してコンソールウィンドウのハンドルを取得し、そのハンドルを SetForegroundWindow 関数に渡すことで、コンソールウィンドウを強制的に前面に表示してフォーカスを割り当てます。アプリケーションがデタッチされたプロセスで実行されていてウィンドウを持たない場合や、Windows サービスである場合は、WinBioAcquireFocus と WinBioReleaseFocus を使用してフォーカスを手動で制御します。

WinBioEnrollCapture を同期的に使用するには、WinBioOpenSession を呼び出して作成したセッションハンドルを指定して、この関数を呼び出します。この関数は、操作が完了するかエラーが発生するまでブロックします。

WinBioEnrollCapture を非同期的に使用するには、WinBioAsyncOpenSession を呼び出して作成したセッションハンドルを指定して、この関数を呼び出します。フレームワークは WINBIO_ASYNC_RESULT 構造体を割り当て、それを使用して操作の成否に関する情報を返します。操作が失敗した場合、フレームワークは入れ子になった EnrollCapture 構造体で WINBIO_REJECT_DETAIL 情報を返します。WINBIO_ASYNC_RESULT 構造体は、WinBioAsyncOpenSession 関数の NotificationMethod パラメーターに設定した値に応じて、アプリケーションのコールバックまたはアプリケーションのメッセージキューに返されます。

メモリリークを防ぐため、WINBIO_ASYNC_RESULT 構造体の使用を終えた後は、コールバックの実装内で WinBioFree を呼び出して構造体を解放する必要があります。

Windows 7: この操作は WinBioEnrollCaptureWithCallback 関数を使用して非同期に実行できます。この関数は入力引数を検証して直ちに制御を返します。入力引数が有効でない場合は、エラーコードを返します。それ以外の場合、フレームワークは別のスレッドで操作を開始します。非同期操作が完了するかエラーが発生すると、フレームワークはアプリケーションが実装した PWINBIO_ENROLL_CAPTURE_CALLBACK 関数に結果を送信します。

例

次の関数は、WinBioEnrollCapture を呼び出してシステムプールにバイオメトリックテンプレートを登録します。Winbio.lib 静的ライブラリにリンクし、次のヘッダーファイルをインクルードしてください。

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;

    // システムプールに接続します。
    hr = WinBioOpenSession( 
            WINBIO_TYPE_FINGERPRINT,    // サービスプロバイダー
            WINBIO_POOL_SYSTEM,         // プールの種類
            WINBIO_FLAG_DEFAULT,        // 構成とアクセス
            NULL,                       // バイオメトリックユニット ID の配列
            0,                          // バイオメトリックユニット ID の数
            NULL,                       // データベース ID
            &sessionHandle              // [out] セッションハンドル
            );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioOpenSession failed. ");
        wprintf_s(L"hr = 0x%x\n", hr);
        goto e_Exit;
    }

    // センサーを検出します。
    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;
    }

    // 登録シーケンスを開始します。
    wprintf_s(L"\n Starting enrollment sequence...\n");
    hr = WinBioEnrollBegin(
            sessionHandle,      // オープンされたバイオメトリックセッションのハンドル
            subFactor,          // テンプレートを作成する対象の指
            unitId              // バイオメトリックユニット ID
            );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioEnrollBegin failed. hr = 0x%x\n", hr);
        goto e_Exit;
    }

    // WinBioEnrollBegin 関数の subFactor 引数で指定した指で
    // センサーをスワイプし、登録情報をキャプチャします。
    //
    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,  // オープンされたバイオメトリックセッションのハンドル
                &rejectDetail   // [out] 失敗情報
                );

        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;
        }
    }

    // 対応するフラグが設定されている場合は登録を破棄します。
    // 破棄しない場合は登録をコミットします。
    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,      // オープンされたバイオメトリックセッションのハンドル
                &identity,          // ユーザーの WINBIO_IDENTITY オブジェクト
                &isNewTemplate);    // 新しいテンプレートかどうか

        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;
}

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// winbio.dll
#include <windows.h>

HRESULT WinBioEnrollCapture(
    DWORD SessionHandle,
    DWORD* RejectDetail   // optional
);
[DllImport("winbio.dll", ExactSpelling = true)]
static extern int WinBioEnrollCapture(
    uint SessionHandle,   // DWORD
    IntPtr RejectDetail   // DWORD* optional, out
);
<DllImport("winbio.dll", ExactSpelling:=True)>
Public Shared Function WinBioEnrollCapture(
    SessionHandle As UInteger,   ' DWORD
    RejectDetail As IntPtr   ' DWORD* optional, out
) As Integer
End Function
' SessionHandle : DWORD
' RejectDetail : DWORD* optional, out
Declare PtrSafe Function WinBioEnrollCapture Lib "winbio" ( _
    ByVal SessionHandle As Long, _
    ByVal RejectDetail As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WinBioEnrollCapture = ctypes.windll.winbio.WinBioEnrollCapture
WinBioEnrollCapture.restype = ctypes.c_int
WinBioEnrollCapture.argtypes = [
    wintypes.DWORD,  # SessionHandle : DWORD
    ctypes.POINTER(wintypes.DWORD),  # RejectDetail : DWORD* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('winbio.dll')
WinBioEnrollCapture = Fiddle::Function.new(
  lib['WinBioEnrollCapture'],
  [
    -Fiddle::TYPE_INT,  # SessionHandle : DWORD
    Fiddle::TYPE_VOIDP,  # RejectDetail : DWORD* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "winbio")]
extern "system" {
    fn WinBioEnrollCapture(
        SessionHandle: u32,  // DWORD
        RejectDetail: *mut u32  // DWORD* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("winbio.dll")]
public static extern int WinBioEnrollCapture(uint SessionHandle, IntPtr RejectDetail);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winbio_WinBioEnrollCapture' -Namespace Win32 -PassThru
# $api::WinBioEnrollCapture(SessionHandle, RejectDetail)
#uselib "winbio.dll"
#func global WinBioEnrollCapture "WinBioEnrollCapture" sptr, sptr
; WinBioEnrollCapture SessionHandle, varptr(RejectDetail)   ; 戻り値は stat
; SessionHandle : DWORD -> "sptr"
; RejectDetail : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "winbio.dll"
#cfunc global WinBioEnrollCapture "WinBioEnrollCapture" int, var
; res = WinBioEnrollCapture(SessionHandle, RejectDetail)
; SessionHandle : DWORD -> "int"
; RejectDetail : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT WinBioEnrollCapture(DWORD SessionHandle, DWORD* RejectDetail)
#uselib "winbio.dll"
#cfunc global WinBioEnrollCapture "WinBioEnrollCapture" int, var
; res = WinBioEnrollCapture(SessionHandle, RejectDetail)
; SessionHandle : DWORD -> "int"
; RejectDetail : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winbio = windows.NewLazySystemDLL("winbio.dll")
	procWinBioEnrollCapture = winbio.NewProc("WinBioEnrollCapture")
)

// SessionHandle (DWORD), RejectDetail (DWORD* optional, out)
r1, _, err := procWinBioEnrollCapture.Call(
	uintptr(SessionHandle),
	uintptr(RejectDetail),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function WinBioEnrollCapture(
  SessionHandle: DWORD;   // DWORD
  RejectDetail: Pointer   // DWORD* optional, out
): Integer; stdcall;
  external 'winbio.dll' name 'WinBioEnrollCapture';
result := DllCall("winbio\WinBioEnrollCapture"
    , "UInt", SessionHandle   ; DWORD
    , "Ptr", RejectDetail   ; DWORD* optional, out
    , "Int")   ; return: HRESULT
●WinBioEnrollCapture(SessionHandle, RejectDetail) = DLL("winbio.dll", "int WinBioEnrollCapture(dword, void*)")
# 呼び出し: WinBioEnrollCapture(SessionHandle, RejectDetail)
# SessionHandle : DWORD -> "dword"
# RejectDetail : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "winbio" fn WinBioEnrollCapture(
    SessionHandle: u32, // DWORD
    RejectDetail: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc WinBioEnrollCapture(
    SessionHandle: uint32,  # DWORD
    RejectDetail: ptr uint32  # DWORD* optional, out
): int32 {.importc: "WinBioEnrollCapture", stdcall, dynlib: "winbio.dll".}
pragma(lib, "winbio");
extern(Windows)
int WinBioEnrollCapture(
    uint SessionHandle,   // DWORD
    uint* RejectDetail   // DWORD* optional, out
);
ccall((:WinBioEnrollCapture, "winbio.dll"), stdcall, Int32,
      (UInt32, Ptr{UInt32}),
      SessionHandle, RejectDetail)
# SessionHandle : DWORD -> UInt32
# RejectDetail : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WinBioEnrollCapture(
    uint32_t SessionHandle,
    uint32_t* RejectDetail);
]]
local winbio = ffi.load("winbio")
-- winbio.WinBioEnrollCapture(SessionHandle, RejectDetail)
-- SessionHandle : DWORD
-- RejectDetail : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('winbio.dll');
const WinBioEnrollCapture = lib.func('__stdcall', 'WinBioEnrollCapture', 'int32_t', ['uint32_t', 'uint32_t *']);
// WinBioEnrollCapture(SessionHandle, RejectDetail)
// SessionHandle : DWORD -> 'uint32_t'
// RejectDetail : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("winbio.dll", {
  WinBioEnrollCapture: { parameters: ["u32", "pointer"], result: "i32" },
});
// lib.symbols.WinBioEnrollCapture(SessionHandle, RejectDetail)
// SessionHandle : DWORD -> "u32"
// RejectDetail : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WinBioEnrollCapture(
    uint32_t SessionHandle,
    uint32_t* RejectDetail);
C, "winbio.dll");
// $ffi->WinBioEnrollCapture(SessionHandle, RejectDetail);
// SessionHandle : DWORD
// RejectDetail : DWORD* optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Winbio extends StdCallLibrary {
    Winbio INSTANCE = Native.load("winbio", Winbio.class);
    int WinBioEnrollCapture(
        int SessionHandle,   // DWORD
        IntByReference RejectDetail   // DWORD* optional, out
    );
}
@[Link("winbio")]
lib Libwinbio
  fun WinBioEnrollCapture = WinBioEnrollCapture(
    SessionHandle : UInt32,   # DWORD
    RejectDetail : UInt32*   # DWORD* optional, out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WinBioEnrollCaptureNative = Int32 Function(Uint32, Pointer<Uint32>);
typedef WinBioEnrollCaptureDart = int Function(int, Pointer<Uint32>);
final WinBioEnrollCapture = DynamicLibrary.open('winbio.dll')
    .lookupFunction<WinBioEnrollCaptureNative, WinBioEnrollCaptureDart>('WinBioEnrollCapture');
// SessionHandle : DWORD -> Uint32
// RejectDetail : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WinBioEnrollCapture(
  SessionHandle: DWORD;   // DWORD
  RejectDetail: Pointer   // DWORD* optional, out
): Integer; stdcall;
  external 'winbio.dll' name 'WinBioEnrollCapture';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WinBioEnrollCapture"
  c_WinBioEnrollCapture :: Word32 -> Ptr Word32 -> IO Int32
-- SessionHandle : DWORD -> Word32
-- RejectDetail : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let winbioenrollcapture =
  foreign "WinBioEnrollCapture"
    (uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* SessionHandle : DWORD -> uint32_t *)
(* RejectDetail : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winbio (t "winbio.dll"))
(cffi:use-foreign-library winbio)

(cffi:defcfun ("WinBioEnrollCapture" win-bio-enroll-capture :convention :stdcall) :int32
  (session-handle :uint32)   ; DWORD
  (reject-detail :pointer))   ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WinBioEnrollCapture = Win32::API::More->new('winbio',
    'int WinBioEnrollCapture(DWORD SessionHandle, LPVOID RejectDetail)');
# my $ret = $WinBioEnrollCapture->Call($SessionHandle, $RejectDetail);
# SessionHandle : DWORD -> DWORD
# RejectDetail : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目