WinBioEnrollBegin
関数シグネチャ
// winbio.dll
#include <windows.h>
HRESULT WinBioEnrollBegin(
DWORD SessionHandle,
BYTE SubFactor,
DWORD UnitId
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| SessionHandle | DWORD | in | 開いている生体認証セッションを識別する WINBIO_SESSION_HANDLE 値です。同期セッションハンドルは WinBioOpenSession を呼び出して開きます。非同期セッションハンドルは WinBioAsyncOpenSession を呼び出して開きます。 |
| SubFactor | BYTE | in | 登録に関する追加情報を提供する WINBIO_BIOMETRIC_SUBTYPE 値です。次のいずれかの値である必要があります。
|
| UnitId | DWORD | in | バイオメトリックユニットを識別する WINBIO_UNIT_ID 値です。この値に 0 を指定することはできません。ユニット ID は WinBioEnumBiometricUnits 関数または WinBioLocateSensor 関数を呼び出して取得できます。 |
戻り値の型: HRESULT
公式ドキュメント
生体認証の登録シーケンスを開始し、空のバイオメトリックテンプレートを作成します。Windows 10 ビルド 1607 以降、この関数はモバイルイメージで使用できます。
戻り値
関数が成功すると S_OK を返します。関数が失敗すると、エラーを示す HRESULT 値を返します。返される値には次の表のものが含まれますが、これらに限定されません。一般的なエラーコードの一覧については、Common HRESULT Values を参照してください。
| リターンコード | 説明 |
|---|---|
| 呼び出し元に登録を行うアクセス許可がありません。 | |
| セッションハンドルが有効ではありません。 | |
| SubFactor パラメーターに WINBIO_SUBTYPE_NO_INFORMATION または WINBIO_SUBTYPE_ANY を指定することはできません。また、UnitId パラメーターに 0 を指定することもできません。 | |
| 登録操作がすでに進行中です。登録は同時に 1 つしか実行できません。 | |
| バイオメトリックユニットが使用中で、ロックされています。 |
解説(Remarks)
1 回の生体認証登録では、ユーザーから複数のサンプルを収集する必要があります。登録操作は同時に 1 つしか実行できず、1 回の登録に属するすべてのバイオメトリックサンプルは同じセンサーで生成される必要があります。このセンサーは UnitId パラメーターで指定します。
システムプール内のバイオメトリックユニットを使用して登録を行うアプリケーションは、WinBioEnrollBegin を呼び出す時点でウィンドウフォーカスを持っている必要があります。フォーカスがない場合、この呼び出しはアプリケーションがウィンドウフォーカスを取得し、ユーザーがバイオメトリックサンプルを提供するまでブロックします。そのため、アプリケーションはフォーカスを取得するまで WinBioEnrollBegin を呼び出さないことをお勧めします。フォーカスを取得する方法は、作成するアプリケーションの種類によって異なります。たとえば、GUI アプリケーションを作成する場合は、WM_ACTIVATE、WM_SETFOCUS、またはその他の適切なメッセージを処理するメッセージハンドラーを実装できます。CUI アプリケーションを作成する場合は、GetConsoleWindow を呼び出してコンソールウィンドウのハンドルを取得し、そのハンドルを SetForegroundWindow 関数に渡して、コンソールウィンドウを強制的に前面に表示してフォーカスを与えます。アプリケーションがデタッチされたプロセスで実行されていてウィンドウを持たない場合や、Windows サービスである場合は、WinBioAcquireFocus と WinBioReleaseFocus を使用してフォーカスを手動で制御します。
WinBioEnrollBegin を同期的に使用するには、WinBioOpenSession を呼び出して作成したセッションハンドルを指定して関数を呼び出します。この関数は、操作が完了するかエラーが発生するまでブロックします。
WinBioEnrollBegin を非同期的に使用するには、WinBioAsyncOpenSession を呼び出して作成したセッションハンドルを指定して関数を呼び出します。フレームワークは WINBIO_ASYNC_RESULT 構造体を割り当て、それを使用して操作の成否に関する情報を返します。操作が成功した場合、フレームワークは入れ子になった EnrollBegin 構造体で WINBIO_BIOMETRIC_SUBTYPE 情報を返します。操作が失敗した場合、フレームワークはエラー情報を返します。WINBIO_ASYNC_RESULT 構造体は、WinBioAsyncOpenSession 関数の NotificationMethod パラメーターに設定した値に応じて、アプリケーションのコールバックまたはアプリケーションのメッセージキューに返されます。
- コールバックを使用して完了通知を受け取る場合は、PWINBIO_ASYNC_COMPLETION_CALLBACK 関数を実装し、NotificationMethod パラメーターに WINBIO_ASYNC_NOTIFY_CALLBACK を設定する必要があります。
- アプリケーションのメッセージキューを使用して完了通知を受け取る場合は、NotificationMethod パラメーターに WINBIO_ASYNC_NOTIFY_MESSAGE を設定する必要があります。フレームワークは、ウィンドウメッセージの LPARAM フィールドに WINBIO_ASYNC_RESULT ポインターを返します。
例
次の関数は、システムプールにバイオメトリックテンプレートを登録します。WinBioEnrollBegin を呼び出して登録シーケンスを開始します。Winbio.lib スタティックライブラリにリンクし、次のヘッダーファイルをインクルードしてください。
- Windows.h
- Stdio.h
- Conio.h
- Winbio.h
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;
// 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. ");
wprintf_s(L"hr = 0x%x\n", hr);
goto e_Exit;
}
// Locate a sensor.
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;
}
// Begin the enrollment sequence.
wprintf_s(L"\n Starting enrollment sequence...\n");
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;
}
// Capture enrollment information by swiping the sensor with
// the finger identified by the subFactor argument in the
// WinBioEnrollBegin function.
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, // Handle to open biometric session
&rejectDetail // [out] Failure information
);
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;
}
}
// Discard the enrollment if the appropriate flag is set.
// Commit the enrollment if it is not discarded.
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, // 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" Press any key to continue...");
_getch();
return hr;
}
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// winbio.dll
#include <windows.h>
HRESULT WinBioEnrollBegin(
DWORD SessionHandle,
BYTE SubFactor,
DWORD UnitId
);[DllImport("winbio.dll", ExactSpelling = true)]
static extern int WinBioEnrollBegin(
uint SessionHandle, // DWORD
byte SubFactor, // BYTE
uint UnitId // DWORD
);<DllImport("winbio.dll", ExactSpelling:=True)>
Public Shared Function WinBioEnrollBegin(
SessionHandle As UInteger, ' DWORD
SubFactor As Byte, ' BYTE
UnitId As UInteger ' DWORD
) As Integer
End Function' SessionHandle : DWORD
' SubFactor : BYTE
' UnitId : DWORD
Declare PtrSafe Function WinBioEnrollBegin Lib "winbio" ( _
ByVal SessionHandle As Long, _
ByVal SubFactor As Byte, _
ByVal UnitId As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WinBioEnrollBegin = ctypes.windll.winbio.WinBioEnrollBegin
WinBioEnrollBegin.restype = ctypes.c_int
WinBioEnrollBegin.argtypes = [
wintypes.DWORD, # SessionHandle : DWORD
ctypes.c_ubyte, # SubFactor : BYTE
wintypes.DWORD, # UnitId : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('winbio.dll')
WinBioEnrollBegin = Fiddle::Function.new(
lib['WinBioEnrollBegin'],
[
-Fiddle::TYPE_INT, # SessionHandle : DWORD
-Fiddle::TYPE_CHAR, # SubFactor : BYTE
-Fiddle::TYPE_INT, # UnitId : DWORD
],
Fiddle::TYPE_INT)#[link(name = "winbio")]
extern "system" {
fn WinBioEnrollBegin(
SessionHandle: u32, // DWORD
SubFactor: u8, // BYTE
UnitId: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("winbio.dll")]
public static extern int WinBioEnrollBegin(uint SessionHandle, byte SubFactor, uint UnitId);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winbio_WinBioEnrollBegin' -Namespace Win32 -PassThru
# $api::WinBioEnrollBegin(SessionHandle, SubFactor, UnitId)#uselib "winbio.dll"
#func global WinBioEnrollBegin "WinBioEnrollBegin" sptr, sptr, sptr
; WinBioEnrollBegin SessionHandle, SubFactor, UnitId ; 戻り値は stat
; SessionHandle : DWORD -> "sptr"
; SubFactor : BYTE -> "sptr"
; UnitId : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "winbio.dll"
#cfunc global WinBioEnrollBegin "WinBioEnrollBegin" int, int, int
; res = WinBioEnrollBegin(SessionHandle, SubFactor, UnitId)
; SessionHandle : DWORD -> "int"
; SubFactor : BYTE -> "int"
; UnitId : DWORD -> "int"; HRESULT WinBioEnrollBegin(DWORD SessionHandle, BYTE SubFactor, DWORD UnitId)
#uselib "winbio.dll"
#cfunc global WinBioEnrollBegin "WinBioEnrollBegin" int, int, int
; res = WinBioEnrollBegin(SessionHandle, SubFactor, UnitId)
; SessionHandle : DWORD -> "int"
; SubFactor : BYTE -> "int"
; UnitId : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winbio = windows.NewLazySystemDLL("winbio.dll")
procWinBioEnrollBegin = winbio.NewProc("WinBioEnrollBegin")
)
// SessionHandle (DWORD), SubFactor (BYTE), UnitId (DWORD)
r1, _, err := procWinBioEnrollBegin.Call(
uintptr(SessionHandle),
uintptr(SubFactor),
uintptr(UnitId),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction WinBioEnrollBegin(
SessionHandle: DWORD; // DWORD
SubFactor: Byte; // BYTE
UnitId: DWORD // DWORD
): Integer; stdcall;
external 'winbio.dll' name 'WinBioEnrollBegin';result := DllCall("winbio\WinBioEnrollBegin"
, "UInt", SessionHandle ; DWORD
, "UChar", SubFactor ; BYTE
, "UInt", UnitId ; DWORD
, "Int") ; return: HRESULT●WinBioEnrollBegin(SessionHandle, SubFactor, UnitId) = DLL("winbio.dll", "int WinBioEnrollBegin(dword, byte, dword)")
# 呼び出し: WinBioEnrollBegin(SessionHandle, SubFactor, UnitId)
# SessionHandle : DWORD -> "dword"
# SubFactor : BYTE -> "byte"
# UnitId : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "winbio" fn WinBioEnrollBegin(
SessionHandle: u32, // DWORD
SubFactor: u8, // BYTE
UnitId: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc WinBioEnrollBegin(
SessionHandle: uint32, # DWORD
SubFactor: uint8, # BYTE
UnitId: uint32 # DWORD
): int32 {.importc: "WinBioEnrollBegin", stdcall, dynlib: "winbio.dll".}pragma(lib, "winbio");
extern(Windows)
int WinBioEnrollBegin(
uint SessionHandle, // DWORD
ubyte SubFactor, // BYTE
uint UnitId // DWORD
);ccall((:WinBioEnrollBegin, "winbio.dll"), stdcall, Int32,
(UInt32, UInt8, UInt32),
SessionHandle, SubFactor, UnitId)
# SessionHandle : DWORD -> UInt32
# SubFactor : BYTE -> UInt8
# UnitId : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t WinBioEnrollBegin(
uint32_t SessionHandle,
uint8_t SubFactor,
uint32_t UnitId);
]]
local winbio = ffi.load("winbio")
-- winbio.WinBioEnrollBegin(SessionHandle, SubFactor, UnitId)
-- SessionHandle : DWORD
-- SubFactor : BYTE
-- UnitId : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('winbio.dll');
const WinBioEnrollBegin = lib.func('__stdcall', 'WinBioEnrollBegin', 'int32_t', ['uint32_t', 'uint8_t', 'uint32_t']);
// WinBioEnrollBegin(SessionHandle, SubFactor, UnitId)
// SessionHandle : DWORD -> 'uint32_t'
// SubFactor : BYTE -> 'uint8_t'
// UnitId : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("winbio.dll", {
WinBioEnrollBegin: { parameters: ["u32", "u8", "u32"], result: "i32" },
});
// lib.symbols.WinBioEnrollBegin(SessionHandle, SubFactor, UnitId)
// SessionHandle : DWORD -> "u32"
// SubFactor : BYTE -> "u8"
// UnitId : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WinBioEnrollBegin(
uint32_t SessionHandle,
uint8_t SubFactor,
uint32_t UnitId);
C, "winbio.dll");
// $ffi->WinBioEnrollBegin(SessionHandle, SubFactor, UnitId);
// SessionHandle : DWORD
// SubFactor : BYTE
// UnitId : DWORD
// 構造体/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 WinBioEnrollBegin(
int SessionHandle, // DWORD
byte SubFactor, // BYTE
int UnitId // DWORD
);
}@[Link("winbio")]
lib Libwinbio
fun WinBioEnrollBegin = WinBioEnrollBegin(
SessionHandle : UInt32, # DWORD
SubFactor : UInt8, # BYTE
UnitId : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WinBioEnrollBeginNative = Int32 Function(Uint32, Uint8, Uint32);
typedef WinBioEnrollBeginDart = int Function(int, int, int);
final WinBioEnrollBegin = DynamicLibrary.open('winbio.dll')
.lookupFunction<WinBioEnrollBeginNative, WinBioEnrollBeginDart>('WinBioEnrollBegin');
// SessionHandle : DWORD -> Uint32
// SubFactor : BYTE -> Uint8
// UnitId : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WinBioEnrollBegin(
SessionHandle: DWORD; // DWORD
SubFactor: Byte; // BYTE
UnitId: DWORD // DWORD
): Integer; stdcall;
external 'winbio.dll' name 'WinBioEnrollBegin';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WinBioEnrollBegin"
c_WinBioEnrollBegin :: Word32 -> Word8 -> Word32 -> IO Int32
-- SessionHandle : DWORD -> Word32
-- SubFactor : BYTE -> Word8
-- UnitId : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let winbioenrollbegin =
foreign "WinBioEnrollBegin"
(uint32_t @-> uint8_t @-> uint32_t @-> returning int32_t)
(* SessionHandle : DWORD -> uint32_t *)
(* SubFactor : BYTE -> uint8_t *)
(* UnitId : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winbio (t "winbio.dll"))
(cffi:use-foreign-library winbio)
(cffi:defcfun ("WinBioEnrollBegin" win-bio-enroll-begin :convention :stdcall) :int32
(session-handle :uint32) ; DWORD
(sub-factor :uint8) ; BYTE
(unit-id :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WinBioEnrollBegin = Win32::API::More->new('winbio',
'int WinBioEnrollBegin(DWORD SessionHandle, BYTE SubFactor, DWORD UnitId)');
# my $ret = $WinBioEnrollBegin->Call($SessionHandle, $SubFactor, $UnitId);
# SessionHandle : DWORD -> DWORD
# SubFactor : BYTE -> BYTE
# UnitId : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f WinBioAcquireFocus — 生体認証操作のフォーカスを取得する。
- f WinBioEnrollCapture — 登録のため生体サンプルを採取する。
- f WinBioEnrollCaptureWithCallback — コールバック方式で登録用の生体サンプルを採取する。
- f WinBioEnrollCommit — 採取した生体情報を登録テンプレートとして確定保存する。
- f WinBioEnrollDiscard — 進行中の生体情報登録を破棄する。
- f WinBioReleaseFocus — 取得していた生体認証操作のフォーカスを解放する。