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

WinBioUnregisterEventMonitor

関数
登録した生体認証イベントモニターを解除する。
DLLwinbio.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT WinBioUnregisterEventMonitor(
    DWORD SessionHandle
);

パラメーター

名前型方向説明
SessionHandleDWORDin開いているバイオメトリックセッションを識別する WINBIO_SESSION_HANDLE 値です。セッションハンドルは WinBioOpenSession を呼び出して開きます。

戻り値の型: HRESULT

公式ドキュメント

開いているバイオメトリックセッションに関連付けられたサービスプロバイダーからのイベント通知をキャンセルします。

戻り値

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

戻り値 説明
E_HANDLE
セッションハンドルが有効ではありません。

解説(Remarks)

イベント通知の受信を開始するには、WinBioRegisterEventMonitor 関数を呼び出します。

アプリケーションが WinBio イベントモニターを登録し、スリープと復帰のサイクル中にそのモニターを有効なままにしておくと、バイオメトリックなプレブート認証 (PBA) やシングルサインオン機能を実装しているシステムで、これらが正しく動作しないことがあります。これは、システムのバイオメトリック資格情報プロバイダーが最初の WinBioIdentify 操作を実行する前に、PBA のバイオメトリック呼び出しがイベントモニターにインターセプトされてしまうためです。WinBio のイベント監視機能を使用するアプリケーションは、システムがスリープする前にモニターの登録を解除し、システムの復帰後に再登録する必要があります。電源状態の変化時におけるイベントの処理については、About Power Management を参照してください。

例

次の関数は、コールバックルーチンのアドレスを渡して WinBioRegisterEventMonitor 関数を呼び出し、イベントモニターを登録します。ここに含めたコールバックは、Windows バイオメトリックフレームワークからイベント通知を受け取ります。またこの関数は、バイオメトリックセッションを閉じる前に WinBioUnregisterEventMonitor を呼び出します。Winbio.lib スタティックライブラリをリンクし、次のヘッダーファイルをインクルードしてください。

HRESULT RegisterSystemEventMonitor(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;
    }

    // Call the WinBioRegisterEventMonitor function.
    wprintf_s(L"\n Calling WinBioRegisterEventMonitor.\n");
    hr = WinBioRegisterEventMonitor(
            sessionHandle,              // Open session handle
            WINBIO_EVENT_FP_UNCLAIMED,  // Events to monitor
            EventMonitorCallback,       // Callback function
            NULL                        // Optional context.
            );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioRegisterEventMonitor failed.");
        wprintf_s(L"hr = 0x%x\n", hr);
        goto e_Exit;
    }
    wprintf_s(L"\n Waiting for an event.\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 an event to happen.
    //wprintf_s(L"\n Swipe the sensor to receive an event notice ");
    //wprintf_s(L"\n or press any key to stop waiting...\n");
    wprintf_s(L"\n Swipe the sensor one or more times ");
    wprintf_s(L"to generate events.");
    wprintf_s(L"\n When done, press a key to exit...\n");
    _getch();

    // Unregister the event monitor.
    wprintf_s(L"\n Calling WinBioUnregisterEventMonitor\n");
    hr = WinBioUnregisterEventMonitor( sessionHandle);
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioUnregisterEventMonitor failed.");
        wprintf_s(L"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 Press any key to exit...");
    _getch();

    return hr;
}

//------------------------------------------------------------------------
// The following function is the callback for WinBioRegisterEventMonitor.
// The function filters any event notice from the biometric subsystem and 
// writes a result to the console window.
// 
VOID CALLBACK EventMonitorCallback(
    __in_opt PVOID EventCallbackContext,
    __in HRESULT OperationStatus,
    __in PWINBIO_EVENT Event
    )
{
    UNREFERENCED_PARAMETER(EventCallbackContext);

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

    // Failure.
    if (FAILED(OperationStatus))
    {
        wprintf_s(L"\n EventMonitorCallback failed. ");
        wprintf_s(L" OperationStatus = 0x%x\n", OperationStatus);
        goto e_Exit;
    }

    // An event notice was received.
    if (Event != NULL)
    {
        wprintf_s(L"\n MonitorEvent: ");
        switch (Event->Type)
        {
            case WINBIO_EVENT_FP_UNCLAIMED:
                wprintf_s(L"WINBIO_EVENT_FP_UNCLAIMED");
                wprintf_s(L"\n Unit ID: %d", 
                          Event->Parameters.Unclaimed.UnitId);
                wprintf_s(L"\n Reject detail: %d\n", 
                          Event->Parameters.Unclaimed.RejectDetail);
                break;

            case WINBIO_EVENT_FP_UNCLAIMED_IDENTIFY:
                wprintf_s(L"WINBIO_EVENT_FP_UNCLAIMED_IDENTIFY");
                wprintf_s(L"\n Unit ID: %d", 
                          Event->Parameters.UnclaimedIdentify.UnitId);
                wprintf_s(L"\n Reject detail: %d\n", 
                          Event->Parameters.UnclaimedIdentify.RejectDetail);
                break;

            case WINBIO_EVENT_ERROR:
                wprintf_s(L"WINBIO_EVENT_ERROR\n");
                break;

            default:
                wprintf_s(L"(0x%08x - Invalid type)\n", Event->Type);
                break;
        }
    }

e_Exit:

    if (Event != NULL)
    {
        //wprintf_s(L"\n Press any key to continue...\n");
        WinBioFree(Event);
        Event = NULL;
    }
}

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

各言語での呼び出し定義

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

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

WinBioUnregisterEventMonitor = ctypes.windll.winbio.WinBioUnregisterEventMonitor
WinBioUnregisterEventMonitor.restype = ctypes.c_int
WinBioUnregisterEventMonitor.argtypes = [
    wintypes.DWORD,  # SessionHandle : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('winbio.dll')
WinBioUnregisterEventMonitor = Fiddle::Function.new(
  lib['WinBioUnregisterEventMonitor'],
  [
    -Fiddle::TYPE_INT,  # SessionHandle : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "winbio")]
extern "system" {
    fn WinBioUnregisterEventMonitor(
        SessionHandle: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("winbio.dll")]
public static extern int WinBioUnregisterEventMonitor(uint SessionHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winbio_WinBioUnregisterEventMonitor' -Namespace Win32 -PassThru
# $api::WinBioUnregisterEventMonitor(SessionHandle)
#uselib "winbio.dll"
#func global WinBioUnregisterEventMonitor "WinBioUnregisterEventMonitor" sptr
; WinBioUnregisterEventMonitor SessionHandle   ; 戻り値は stat
; SessionHandle : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "winbio.dll"
#cfunc global WinBioUnregisterEventMonitor "WinBioUnregisterEventMonitor" int
; res = WinBioUnregisterEventMonitor(SessionHandle)
; SessionHandle : DWORD -> "int"
; HRESULT WinBioUnregisterEventMonitor(DWORD SessionHandle)
#uselib "winbio.dll"
#cfunc global WinBioUnregisterEventMonitor "WinBioUnregisterEventMonitor" int
; res = WinBioUnregisterEventMonitor(SessionHandle)
; SessionHandle : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winbio = windows.NewLazySystemDLL("winbio.dll")
	procWinBioUnregisterEventMonitor = winbio.NewProc("WinBioUnregisterEventMonitor")
)

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

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

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

let winbiounregistereventmonitor =
  foreign "WinBioUnregisterEventMonitor"
    (uint32_t @-> returning int32_t)
(* SessionHandle : 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 ("WinBioUnregisterEventMonitor" win-bio-unregister-event-monitor :convention :stdcall) :int32
  (session-handle :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WinBioUnregisterEventMonitor = Win32::API::More->new('winbio',
    'int WinBioUnregisterEventMonitor(DWORD SessionHandle)');
# my $ret = $WinBioUnregisterEventMonitor->Call($SessionHandle);
# SessionHandle : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目