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

WinBioVerify

関数
指定IDに対し採取した生体情報の一致を検証する。
DLLwinbio.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT WinBioVerify(
    DWORD SessionHandle,
    WINBIO_IDENTITY* Identity,
    BYTE SubFactor,
    DWORD* UnitId,   // optional
    BYTE* Match,   // optional
    DWORD* RejectDetail   // optional
);

パラメーター

名前型方向説明
SessionHandleDWORDin開いている生体認証セッションを識別する WINBIO_SESSION_HANDLE 値です。同期セッションハンドルは WinBioOpenSession を呼び出して開きます。非同期セッションハンドルは WinBioAsyncOpenSession を呼び出して開きます。
IdentityWINBIO_IDENTITY*in生体認証サンプルを提供するユーザーの GUID または SID を格納する WINBIO_IDENTITY 構造体へのポインターです。
SubFactorBYTEin

生体認証サンプルに関連付けられたサブファクターを指定する WINBIO_BIOMETRIC_SUBTYPE 値です。Windows Biometric Framework (WBF) は現在、指紋のキャプチャのみをサポートしており、サブタイプ情報を表すために次の定数を使用できます。

  • WINBIO_ANSI_381_POS_RH_THUMB
  • WINBIO_ANSI_381_POS_RH_INDEX_FINGER
  • WINBIO_ANSI_381_POS_RH_MIDDLE_FINGER
  • WINBIO_ANSI_381_POS_RH_RING_FINGER
  • WINBIO_ANSI_381_POS_RH_LITTLE_FINGER
  • WINBIO_ANSI_381_POS_LH_THUMB
  • WINBIO_ANSI_381_POS_LH_INDEX_FINGER
  • WINBIO_ANSI_381_POS_LH_MIDDLE_FINGER
  • WINBIO_ANSI_381_POS_LH_RING_FINGER
  • WINBIO_ANSI_381_POS_LH_LITTLE_FINGER
  • WINBIO_ANSI_381_POS_RH_FOUR_FINGERS
  • WINBIO_ANSI_381_POS_LH_FOUR_FINGERS
  • WINBIO_SUBTYPE_ANY
UnitIdDWORD*outoptional検証を実行した生体認証ユニットを指定する WINBIO_UNIT_ID 値へのポインターです。
MatchBYTE*outoptionalキャプチャされたサンプルが Identity パラメーターで指定されたユーザー ID と一致したかどうかを示すブール値へのポインターです。
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

公式ドキュメント

生体認証サンプルをキャプチャし、そのサンプルが指定されたユーザー ID に対応するかどうかを判定します。Windows 10 ビルド 1607 以降、この関数はモバイルイメージで使用できます。

戻り値

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

戻り値 説明
E_HANDLE
セッションハンドルが有効ではありません。
E_INVALIDARG
SubFactor 引数が正しくありません。
E_POINTER
UnitId、Identity、SubFactor、RejectDetail の各パラメーターで指定するポインターに NULL を指定することはできません。
WINBIO_E_BAD_CAPTURE
生体認証サンプルをキャプチャできませんでした。詳細については RejectDetail の値を使用してください。
WINBIO_E_ENROLLMENT_IN_PROGRESS
指定された生体認証ユニットが現在、登録トランザクションで使用されているため、操作を完了できませんでした (システムプールのみ)。
WINBIO_E_NO_MATCH
生体認証サンプルは、指定された Identity と SubFactor の組み合わせに対応していません。

解説(Remarks)

生体認証サンプルのキャプチャに失敗した場合、UnitId パラメーターには、キャプチャを試みたセンサーのユニット番号が格納されます。

システムプールを使用してこの関数を呼び出すと、アプリケーションがウィンドウフォーカスを取得し、ユーザーが生体認証サンプルを提供するまでブロックされます。そのため、アプリケーションはフォーカスを取得するまで WinBioVerify を呼び出さないことをお勧めします。フォーカスを取得する方法は、作成するアプリケーションの種類によって異なります。たとえば、GUI アプリケーションを作成する場合は、WM_ACTIVATE、WM_SETFOCUS などの適切なメッセージを受け取るメッセージハンドラーを実装できます。CUI アプリケーションを作成する場合は、GetConsoleWindow を呼び出してコンソールウィンドウのハンドルを取得し、そのハンドルを SetForegroundWindow 関数に渡して、コンソールウィンドウを強制的に前面に移動させてフォーカスを割り当てます。アプリケーションがウィンドウを持たない分離されたプロセスで実行されている場合や Windows サービスである場合は、WinBioAcquireFocus と WinBioReleaseFocus を使用してフォーカスを手動で制御します。

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

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

メモリリークを防ぐため、WINBIO_ASYNC_RESULT 構造体の使用が終わったら、WinBioFree を呼び出して解放する必要があります。

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

例

次の関数は、WinBioVerify を呼び出して、生体認証サンプルが現在ログオンしているユーザーの ID と一致するかどうかを判定します。ヘルパー関数 GetCurrentUserIdentity も含まれています。Winbio.lib 静的ライブラリにリンクし、次のヘッダーファイルをインクルードしてください。

HRESULT Verify(WINBIO_BIOMETRIC_SUBTYPE subFactor)
{
    HRESULT hr = S_OK;
    WINBIO_SESSION_HANDLE sessionHandle = NULL;
    WINBIO_UNIT_ID unitId = 0;
    WINBIO_REJECT_DETAIL rejectDetail = 0;
    WINBIO_IDENTITY identity = {0};
    BOOLEAN match = FALSE;

    // Find the identity of the user.
    hr = GetCurrentUserIdentity( &identity );
    if (FAILED(hr))
    {
        wprintf_s(L"\n User identity not found. hr = 0x%x\n", hr);
        goto e_Exit;
    }

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

    // Verify a biometric sample.
    wprintf_s(L"\n Calling WinBioVerify - Swipe finger on sensor...\n");
    hr = WinBioVerify( 
            sessionHandle, 
            &identity, 
            subFactor, 
            &unitId, 
            &match,
            &rejectDetail
            );
    wprintf_s(L"\n Swipe processed - Unit ID: %d\n", unitId);
    if (FAILED(hr))
    {
        if (hr == WINBIO_E_NO_MATCH)
        {
            wprintf_s(L"\n- NO MATCH - identity verification failed.\n");
        }
        else if (hr == WINBIO_E_BAD_CAPTURE)
        {
            wprintf_s(L"\n- Bad capture; reason: %d\n", rejectDetail);
        }
        else
        {
        wprintf_s(L"\n WinBioVerify failed. hr = 0x%x\n", hr);
        }
        goto e_Exit;
    }
    wprintf_s(L"\n Fingerprint verified:\n", unitId);


e_Exit:
    if (sessionHandle != NULL)
    {
        WinBioCloseSession(sessionHandle);
        sessionHandle = NULL;
    }

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

    return hr;
}

//------------------------------------------------------------------------
// The following function retrieves the identity of the current user.
// This is a helper function and is not part of the Windows Biometric
// Framework API.
//
HRESULT GetCurrentUserIdentity(__inout PWINBIO_IDENTITY Identity)
{
    // Declare variables.
    HRESULT hr = S_OK;
    HANDLE tokenHandle = NULL;
    DWORD bytesReturned = 0;
    struct{
        TOKEN_USER tokenUser;
        BYTE buffer[SECURITY_MAX_SID_SIZE];
    } tokenInfoBuffer;

    // Zero the input identity and specify the type.
    ZeroMemory( Identity, sizeof(WINBIO_IDENTITY));
    Identity->Type = WINBIO_ID_TYPE_NULL;

    // Open the access token associated with the
    // current process
    if (!OpenProcessToken(
            GetCurrentProcess(),            // Process handle
            TOKEN_READ,                     // Read access only
            &tokenHandle))                  // Access token handle
    {
        DWORD win32Status = GetLastError();
        wprintf_s(L"Cannot open token handle: %d\n", win32Status);
        hr = HRESULT_FROM_WIN32(win32Status);
        goto e_Exit;
    }

    // Zero the tokenInfoBuffer structure.
    ZeroMemory(&tokenInfoBuffer, sizeof(tokenInfoBuffer));

    // Retrieve information about the access token. In this case,
    // retrieve a SID.
    if (!GetTokenInformation(
            tokenHandle,                    // Access token handle
            TokenUser,                      // User for the token
            &tokenInfoBuffer.tokenUser,     // Buffer to fill
            sizeof(tokenInfoBuffer),        // Size of the buffer
            &bytesReturned))                // Size needed
    {
        DWORD win32Status = GetLastError();
        wprintf_s(L"Cannot query token information: %d\n", win32Status);
        hr = HRESULT_FROM_WIN32(win32Status);
        goto e_Exit;
    }

    // Copy the SID from the tokenInfoBuffer structure to the
    // WINBIO_IDENTITY structure. 
    CopySid(
        SECURITY_MAX_SID_SIZE,
        Identity->Value.AccountSid.Data,
        tokenInfoBuffer.tokenUser.User.Sid
        );

    // Specify the size of the SID and assign WINBIO_ID_TYPE_SID
    // to the type member of the WINBIO_IDENTITY structure.
    Identity->Value.AccountSid.Size = GetLengthSid(tokenInfoBuffer.tokenUser.User.Sid);
    Identity->Type = WINBIO_ID_TYPE_SID;

e_Exit:

    if (tokenHandle != NULL)
    {
        CloseHandle(tokenHandle);
    }

    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 WinBioVerify(
    DWORD SessionHandle,
    WINBIO_IDENTITY* Identity,
    BYTE SubFactor,
    DWORD* UnitId,   // optional
    BYTE* Match,   // optional
    DWORD* RejectDetail   // optional
);
[DllImport("winbio.dll", ExactSpelling = true)]
static extern int WinBioVerify(
    uint SessionHandle,   // DWORD
    IntPtr Identity,   // WINBIO_IDENTITY*
    byte SubFactor,   // BYTE
    IntPtr UnitId,   // DWORD* optional, out
    IntPtr Match,   // BYTE* optional, out
    IntPtr RejectDetail   // DWORD* optional, out
);
<DllImport("winbio.dll", ExactSpelling:=True)>
Public Shared Function WinBioVerify(
    SessionHandle As UInteger,   ' DWORD
    Identity As IntPtr,   ' WINBIO_IDENTITY*
    SubFactor As Byte,   ' BYTE
    UnitId As IntPtr,   ' DWORD* optional, out
    Match As IntPtr,   ' BYTE* optional, out
    RejectDetail As IntPtr   ' DWORD* optional, out
) As Integer
End Function
' SessionHandle : DWORD
' Identity : WINBIO_IDENTITY*
' SubFactor : BYTE
' UnitId : DWORD* optional, out
' Match : BYTE* optional, out
' RejectDetail : DWORD* optional, out
Declare PtrSafe Function WinBioVerify Lib "winbio" ( _
    ByVal SessionHandle As Long, _
    ByVal Identity As LongPtr, _
    ByVal SubFactor As Byte, _
    ByVal UnitId As LongPtr, _
    ByVal Match As LongPtr, _
    ByVal RejectDetail As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WinBioVerify = ctypes.windll.winbio.WinBioVerify
WinBioVerify.restype = ctypes.c_int
WinBioVerify.argtypes = [
    wintypes.DWORD,  # SessionHandle : DWORD
    ctypes.c_void_p,  # Identity : WINBIO_IDENTITY*
    ctypes.c_ubyte,  # SubFactor : BYTE
    ctypes.POINTER(wintypes.DWORD),  # UnitId : DWORD* optional, out
    ctypes.POINTER(ctypes.c_ubyte),  # Match : BYTE* optional, out
    ctypes.POINTER(wintypes.DWORD),  # RejectDetail : DWORD* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('winbio.dll')
WinBioVerify = Fiddle::Function.new(
  lib['WinBioVerify'],
  [
    -Fiddle::TYPE_INT,  # SessionHandle : DWORD
    Fiddle::TYPE_VOIDP,  # Identity : WINBIO_IDENTITY*
    -Fiddle::TYPE_CHAR,  # SubFactor : BYTE
    Fiddle::TYPE_VOIDP,  # UnitId : DWORD* optional, out
    Fiddle::TYPE_VOIDP,  # Match : BYTE* optional, out
    Fiddle::TYPE_VOIDP,  # RejectDetail : DWORD* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "winbio")]
extern "system" {
    fn WinBioVerify(
        SessionHandle: u32,  // DWORD
        Identity: *mut WINBIO_IDENTITY,  // WINBIO_IDENTITY*
        SubFactor: u8,  // BYTE
        UnitId: *mut u32,  // DWORD* optional, out
        Match: *mut u8,  // BYTE* optional, out
        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 WinBioVerify(uint SessionHandle, IntPtr Identity, byte SubFactor, IntPtr UnitId, IntPtr Match, IntPtr RejectDetail);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winbio_WinBioVerify' -Namespace Win32 -PassThru
# $api::WinBioVerify(SessionHandle, Identity, SubFactor, UnitId, Match, RejectDetail)
#uselib "winbio.dll"
#func global WinBioVerify "WinBioVerify" sptr, sptr, sptr, sptr, sptr, sptr
; WinBioVerify SessionHandle, varptr(Identity), SubFactor, varptr(UnitId), varptr(Match), varptr(RejectDetail)   ; 戻り値は stat
; SessionHandle : DWORD -> "sptr"
; Identity : WINBIO_IDENTITY* -> "sptr"
; SubFactor : BYTE -> "sptr"
; UnitId : DWORD* optional, out -> "sptr"
; Match : BYTE* optional, out -> "sptr"
; RejectDetail : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "winbio.dll"
#cfunc global WinBioVerify "WinBioVerify" int, var, int, var, var, var
; res = WinBioVerify(SessionHandle, Identity, SubFactor, UnitId, Match, RejectDetail)
; SessionHandle : DWORD -> "int"
; Identity : WINBIO_IDENTITY* -> "var"
; SubFactor : BYTE -> "int"
; UnitId : DWORD* optional, out -> "var"
; Match : BYTE* optional, out -> "var"
; RejectDetail : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT WinBioVerify(DWORD SessionHandle, WINBIO_IDENTITY* Identity, BYTE SubFactor, DWORD* UnitId, BYTE* Match, DWORD* RejectDetail)
#uselib "winbio.dll"
#cfunc global WinBioVerify "WinBioVerify" int, var, int, var, var, var
; res = WinBioVerify(SessionHandle, Identity, SubFactor, UnitId, Match, RejectDetail)
; SessionHandle : DWORD -> "int"
; Identity : WINBIO_IDENTITY* -> "var"
; SubFactor : BYTE -> "int"
; UnitId : DWORD* optional, out -> "var"
; Match : BYTE* optional, out -> "var"
; RejectDetail : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winbio = windows.NewLazySystemDLL("winbio.dll")
	procWinBioVerify = winbio.NewProc("WinBioVerify")
)

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

extern "winbio" fn WinBioVerify(
    SessionHandle: u32, // DWORD
    Identity: [*c]WINBIO_IDENTITY, // WINBIO_IDENTITY*
    SubFactor: u8, // BYTE
    UnitId: [*c]u32, // DWORD* optional, out
    Match: [*c]u8, // BYTE* optional, out
    RejectDetail: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc WinBioVerify(
    SessionHandle: uint32,  # DWORD
    Identity: ptr WINBIO_IDENTITY,  # WINBIO_IDENTITY*
    SubFactor: uint8,  # BYTE
    UnitId: ptr uint32,  # DWORD* optional, out
    Match: ptr uint8,  # BYTE* optional, out
    RejectDetail: ptr uint32  # DWORD* optional, out
): int32 {.importc: "WinBioVerify", stdcall, dynlib: "winbio.dll".}
pragma(lib, "winbio");
extern(Windows)
int WinBioVerify(
    uint SessionHandle,   // DWORD
    WINBIO_IDENTITY* Identity,   // WINBIO_IDENTITY*
    ubyte SubFactor,   // BYTE
    uint* UnitId,   // DWORD* optional, out
    ubyte* Match,   // BYTE* optional, out
    uint* RejectDetail   // DWORD* optional, out
);
ccall((:WinBioVerify, "winbio.dll"), stdcall, Int32,
      (UInt32, Ptr{WINBIO_IDENTITY}, UInt8, Ptr{UInt32}, Ptr{UInt8}, Ptr{UInt32}),
      SessionHandle, Identity, SubFactor, UnitId, Match, RejectDetail)
# SessionHandle : DWORD -> UInt32
# Identity : WINBIO_IDENTITY* -> Ptr{WINBIO_IDENTITY}
# SubFactor : BYTE -> UInt8
# UnitId : DWORD* optional, out -> Ptr{UInt32}
# Match : BYTE* optional, out -> Ptr{UInt8}
# RejectDetail : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WinBioVerify(
    uint32_t SessionHandle,
    void* Identity,
    uint8_t SubFactor,
    uint32_t* UnitId,
    uint8_t* Match,
    uint32_t* RejectDetail);
]]
local winbio = ffi.load("winbio")
-- winbio.WinBioVerify(SessionHandle, Identity, SubFactor, UnitId, Match, RejectDetail)
-- SessionHandle : DWORD
-- Identity : WINBIO_IDENTITY*
-- SubFactor : BYTE
-- UnitId : DWORD* optional, out
-- Match : BYTE* optional, out
-- RejectDetail : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('winbio.dll');
const WinBioVerify = lib.func('__stdcall', 'WinBioVerify', 'int32_t', ['uint32_t', 'void *', 'uint8_t', 'uint32_t *', 'uint8_t *', 'uint32_t *']);
// WinBioVerify(SessionHandle, Identity, SubFactor, UnitId, Match, RejectDetail)
// SessionHandle : DWORD -> 'uint32_t'
// Identity : WINBIO_IDENTITY* -> 'void *'
// SubFactor : BYTE -> 'uint8_t'
// UnitId : DWORD* optional, out -> 'uint32_t *'
// Match : BYTE* optional, out -> 'uint8_t *'
// RejectDetail : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("winbio.dll", {
  WinBioVerify: { parameters: ["u32", "pointer", "u8", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.WinBioVerify(SessionHandle, Identity, SubFactor, UnitId, Match, RejectDetail)
// SessionHandle : DWORD -> "u32"
// Identity : WINBIO_IDENTITY* -> "pointer"
// SubFactor : BYTE -> "u8"
// UnitId : DWORD* optional, out -> "pointer"
// Match : BYTE* optional, out -> "pointer"
// RejectDetail : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WinBioVerify(
    uint32_t SessionHandle,
    void* Identity,
    uint8_t SubFactor,
    uint32_t* UnitId,
    uint8_t* Match,
    uint32_t* RejectDetail);
C, "winbio.dll");
// $ffi->WinBioVerify(SessionHandle, Identity, SubFactor, UnitId, Match, RejectDetail);
// SessionHandle : DWORD
// Identity : WINBIO_IDENTITY*
// SubFactor : BYTE
// UnitId : DWORD* optional, out
// Match : BYTE* optional, out
// 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 WinBioVerify(
        int SessionHandle,   // DWORD
        Pointer Identity,   // WINBIO_IDENTITY*
        byte SubFactor,   // BYTE
        IntByReference UnitId,   // DWORD* optional, out
        byte[] Match,   // BYTE* optional, out
        IntByReference RejectDetail   // DWORD* optional, out
    );
}
@[Link("winbio")]
lib Libwinbio
  fun WinBioVerify = WinBioVerify(
    SessionHandle : UInt32,   # DWORD
    Identity : WINBIO_IDENTITY*,   # WINBIO_IDENTITY*
    SubFactor : UInt8,   # BYTE
    UnitId : UInt32*,   # DWORD* optional, out
    Match : UInt8*,   # BYTE* optional, out
    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 WinBioVerifyNative = Int32 Function(Uint32, Pointer<Void>, Uint8, Pointer<Uint32>, Pointer<Uint8>, Pointer<Uint32>);
typedef WinBioVerifyDart = int Function(int, Pointer<Void>, int, Pointer<Uint32>, Pointer<Uint8>, Pointer<Uint32>);
final WinBioVerify = DynamicLibrary.open('winbio.dll')
    .lookupFunction<WinBioVerifyNative, WinBioVerifyDart>('WinBioVerify');
// SessionHandle : DWORD -> Uint32
// Identity : WINBIO_IDENTITY* -> Pointer<Void>
// SubFactor : BYTE -> Uint8
// UnitId : DWORD* optional, out -> Pointer<Uint32>
// Match : BYTE* optional, out -> Pointer<Uint8>
// RejectDetail : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WinBioVerify(
  SessionHandle: DWORD;   // DWORD
  Identity: Pointer;   // WINBIO_IDENTITY*
  SubFactor: Byte;   // BYTE
  UnitId: Pointer;   // DWORD* optional, out
  Match: Pointer;   // BYTE* optional, out
  RejectDetail: Pointer   // DWORD* optional, out
): Integer; stdcall;
  external 'winbio.dll' name 'WinBioVerify';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let winbioverify =
  foreign "WinBioVerify"
    (uint32_t @-> (ptr void) @-> uint8_t @-> (ptr uint32_t) @-> (ptr uint8_t) @-> (ptr uint32_t) @-> returning int32_t)
(* SessionHandle : DWORD -> uint32_t *)
(* Identity : WINBIO_IDENTITY* -> (ptr void) *)
(* SubFactor : BYTE -> uint8_t *)
(* UnitId : DWORD* optional, out -> (ptr uint32_t) *)
(* Match : BYTE* optional, out -> (ptr uint8_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 ("WinBioVerify" win-bio-verify :convention :stdcall) :int32
  (session-handle :uint32)   ; DWORD
  (identity :pointer)   ; WINBIO_IDENTITY*
  (sub-factor :uint8)   ; BYTE
  (unit-id :pointer)   ; DWORD* optional, out
  (match :pointer)   ; BYTE* optional, out
  (reject-detail :pointer))   ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WinBioVerify = Win32::API::More->new('winbio',
    'int WinBioVerify(DWORD SessionHandle, LPVOID Identity, BYTE SubFactor, LPVOID UnitId, LPVOID Match, LPVOID RejectDetail)');
# my $ret = $WinBioVerify->Call($SessionHandle, $Identity, $SubFactor, $UnitId, $Match, $RejectDetail);
# SessionHandle : DWORD -> DWORD
# Identity : WINBIO_IDENTITY* -> LPVOID
# SubFactor : BYTE -> BYTE
# UnitId : DWORD* optional, out -> LPVOID
# Match : BYTE* optional, out -> LPVOID
# RejectDetail : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型