PIBIO_ENGINE_ATTACH_FN
コールバックシグネチャ
HRESULT PIBIO_ENGINE_ATTACH_FN(
WINBIO_PIPELINE* Pipeline
);パラメーター
| フィールド | 型 | 説明 |
|---|---|---|
| Pipeline | WINBIO_PIPELINE* | 操作を実行するバイオメトリックユニットに関連付けられた WINBIO_PIPELINE 構造体へのポインター。 |
公式ドキュメント
バイオメトリックユニットの処理パイプラインにエンジンアダプターが追加されるときに、Windows Biometric Framework によって呼び出されます。この関数の目的は、後続のバイオメトリック操作に必要な初期化を行うことです。
戻り値
関数が成功した場合は S_OK を返します。関数が失敗した場合は、エラーを示す次のいずれかの HRESULT 値を返す必要があります。
| 戻り値 | 説明 |
|---|---|
| Pipeline 引数を NULL にすることはできません。 | |
| メモリが不足しているため、操作を完了できませんでした。 | |
| Pipeline 引数が指す WINBIO_PIPELINE 構造体の EngineContext メンバーが NULL でないか、EngineHandle メンバーが INVALID_HANDLE_VALUE に設定されていません。 |
解説(Remarks)
この関数は、バイオメトリックユニットのストレージアダプターが初期化される前に呼び出されます。そのため、この関数からは、パイプラインオブジェクトの StorageInterface メンバーが指す WINBIO_STORAGE_INTERFACE 構造体で参照される関数を呼び出してはなりません。
この関数を実装する際は、アダプターが必要とするリソースを割り当てて管理し、それらをバイオメトリックユニットのパイプラインに関連付ける必要があります。そのためには、プライベートな WINBIO_ENGINE_CONTEXT 構造体をヒープ上に割り当てて初期化し、そのアドレスをパイプラインオブジェクトの EngineContext メンバーに設定します。
この関数で使用するエンジンアダプターのリソースの作成および初期化中にエラーが発生した場合は、戻る前に必要なクリーンアップを行う必要があります。
この関数が呼び出された時点で EngineContext フィールドが NULL でない場合、パイプラインが正しく初期化されていないため、その問題を Windows Biometric Framework に通知するために WINBIO_E_INVALID_DEVICE_STATE を返す必要があります。
同様に、この関数が呼び出された時点で EngineHandle フィールドに INVALID_HANDLE_VALUE が格納されていない場合も、WINBIO_E_INVALID_DEVICE_STATE を返す必要があります。
例
次の擬似コードは、この関数の実装例の 1 つを示しています。このサンプルはコンパイルできません。目的に合わせて適宜変更する必要があります。
//////////////////////////////////////////////////////////////////////////////////////////
//
// EngineAdapterAttach
//
// Purpose:
// Performs any initialization required for later biometric operations.
//
// Parameters:
// Pipeline - Pointer to a WINBIO_PIPELINE structure associated with
// the biometric unit performing the operation.
//
static HRESULT
WINAPI
EngineAdapterAttach(
__inout PWINBIO_PIPELINE Pipeline
)
{
HRESULT hr = S_OK;
// Verify that the Pipeline parameter is not NULL.
if (!ARGUMENT_PRESENT(Pipeline))
{
hr = E_POINTER;
goto cleanup;
}
// Retrieve the context from the pipeline.
PWINBIO_ENGINE_CONTEXT newContext = NULL;
// Call a custom function (_AdapterAlloc) to allocate memory to hold the
// engine adapter context.
newContext = (PWINBIO_ENGINE_CONTEXT)_AdapterAlloc(sizeof(WINBIO_ENGINE_CONTEXT));
if (newContext == NULL)
{
E_OUTOFMEMORY;
goto cleanup;
}
// Clear the context memory.
ZeroMemory(newContext, sizeof(WINBIO_ENGINE_CONTEXT));
// Initialize any required context fields.
newContext->SomeField = SomeSpecialValue;
newContext->SomePointerField = _AdapterAlloc(sizeof(SOME_STRUCTURE));
if (newContext->SomePointerField == NULL)
{
E_OUTOFMEMORY;
goto cleanup;
}
// If your adapter supports software-based template hashing, implement the
// following custom function to open a SHA1 hash object handle and store
// the handle in the adapter context. Use Cryptography Next Generation (CNG)
// functions to create the SHA1 hash object.
hr = _AdapterInitializeCrypto(newContext);
if (FAILED(hr))
{
goto cleanup;
}
// If initialization completes successfully, attach the engine context to the
// processing pipeline of the biometric unit.
Pipeline->EngineContext = newContext;
newContext = NULL;
cleanup:
if (FAILED(hr))
{
// If a new context has been created, release any memory
// pointed to by various data members in the context and
// then release the context. The following example assumes
// that your adapter contains a handle
// for a hash object and a pointer to another object.
if (newContext != NULL)
{
// Close any open CNG handles and release the hash object memory.
_AdapterCleanupCrypto(newContext);
// Release any other object pointed to by the context.
if (newContext->SomePointerField != NULL)
{
_AdapterRelease(newContext->SomePointerField);
}
// Release the context
_AdapterRelease(newContext);
}
}
return hr;
}
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)