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

PIBIO_ENGINE_CONTROL_UNIT_FN

コールバック

シグネチャ

HRESULT PIBIO_ENGINE_CONTROL_UNIT_FN(
    WINBIO_PIPELINE* Pipeline,
    DWORD ControlCode,
    BYTE* SendBuffer,
    UINT_PTR SendBufferSize,
    BYTE* ReceiveBuffer,
    UINT_PTR ReceiveBufferSize,
    UINT_PTR* ReceiveDataSize,
    DWORD* OperationStatus
);

パラメーター

フィールド型説明
PipelineWINBIO_PIPELINE*操作を実行するバイオメトリック ユニットに関連付けられた WINBIO_PIPELINE 構造体へのポインターです。
ControlCodeDWORD実行するベンダー定義の操作を指定する ULONG 値です。
SendBufferBYTE*エンジン アダプターに送信される制御情報を格納したバッファーへのポインターです。バッファーの形式と内容はベンダー定義です。
SendBufferSizeUINT_PTRSendBuffer パラメーターで指定されたバッファーのサイズ (バイト単位) です。
ReceiveBufferBYTE*制御操作に応答してエンジン アダプターが返す情報を受け取るバッファーへのポインターです。バッファーの形式はベンダー定義です。
ReceiveBufferSizeUINT_PTRReceiveBuffer パラメーターで指定されたバッファーのサイズ (バイト単位) です。
ReceiveDataSizeUINT_PTR*ReceiveBuffer パラメーターで指定されたバッファーに書き込まれたデータのサイズ (バイト単位) を受け取る変数へのポインターです。
OperationStatusDWORD*制御操作の結果を示すベンダー定義の状態コードを受け取る変数へのポインターです。

公式ドキュメント

昇格された特権を必要としないベンダー定義の制御操作を実行するために、Windows Biometric Framework から呼び出されます。昇格された特権を必要とするベンダー定義の制御操作を実行するには、EngineAdapterControlUnitPrivileged 関数を呼び出します。

戻り値

関数が成功した場合は S_OK を返します。関数が失敗した場合は、エラーを示す次の HRESULT 値のいずれかを返す必要があります。

戻り値 説明
E_POINTER
必須のポインター引数が NULL です。
E_INVALIDARG
SendBuffer パラメーターで指定されたバッファーのサイズまたは形式が正しくないか、ControlCode パラメーターで指定された値がアダプターで認識されません。
E_NOT_SUFFICIENT_BUFFER
ReceiveBuffer パラメーターで指定されたバッファーが小さすぎます。
WINBIO_E_CANCELED
操作がキャンセルされました。
WINBIO_E_DEVICE_FAILURE
ハードウェア障害が発生しました。
WINBIO_E_INVALID_CONTROL_CODE
ControlCode パラメーターで指定された値がアダプターで認識されません。
注 Windows 8 以降では、この状態を示すには E_INVALIDARG のみを使用してください。

解説(Remarks)

この関数の実装は、EngineAdapterControlUnitPrivileged 関数の実装と同一にする必要がありますが、ControlCode パラメーターで指定された操作の実行に昇格された特権が不要である点が異なります。操作を定義し、どの操作で昇格された特権を不要とするかを決定するのは、実装者の責任です。

この関数は、ReceiveBuffer パラメーターで指定されたバッファーが返されるデータを格納できる十分な大きさであることを確認するため、ReceiveBufferSize パラメーターの値をチェックする必要があります。

例

次の擬似コードは、この関数の実装例の 1 つを示しています。このサンプルはコンパイルできません。目的に合わせて変更して使用してください。

//////////////////////////////////////////////////////////////////////////////////////////
//
// EngineAdapterControlUnit
//
// Purpose:
//      Performs a vendor-defined control operation that does not require 
//      elevated privilege.
//
// Parameters:
//      Pipeline            - Pointer to a WINBIO_PIPELINE structure associated 
//                            with the biometric unit performing the operation
//      ControlCode         - Specifies the vendor-defined operation to perform
//      SendBuffer          - Contains the control information sent to the 
//                            engine adapter
//      SendBufferSize      - Size, in bytes, of the buffer specified by the 
//                            SendBuffer parameter
//      ReceiveBuffer       - Receives information returned by the engine adapter
//                            in response to the control operation
//      ReceiveBufferSize   - Size, in bytes, of the buffer specified by the 
//                            ReceiveBuffer parameter.
//      ReceiveDataSize     - Receives the size, in bytes, of the data written to 
//                            the buffer specified by the ReceiveBuffer parameter
//      OperationStatus     - Receives a vendor-defined status code that specifies 
//                            the outcome of the control operation.
//
static HRESULT
WINAPI
EngineAdapterControlUnit(
    __inout PWINBIO_PIPELINE Pipeline,
    __in ULONG ControlCode,
    __in PUCHAR SendBuffer,
    __in SIZE_T SendBufferSize,
    __in PUCHAR ReceiveBuffer,
    __in SIZE_T ReceiveBufferSize,
    __out PSIZE_T ReceiveDataSize,
    __out PULONG OperationStatus
    )
{
    HRESULT hr = S_OK;
    BOOL result = TRUE;

    // Verify that pointer arguments are not NULL.
    if (!ARGUMENT_PRESENT(Pipeline) ||
        !ARGUMENT_PRESENT(SendBuffer) ||
        !ARGUMENT_PRESENT(ReceiveBuffer) ||
        !ARGUMENT_PRESENT(ReceiveDataSize) ||
        !ARGUMENT_PRESENT(OperationStatus))
    {
        hr = E_POINTER;
        goto cleanup;
    }

    // Retrieve the context from the pipeline.
    PWINBIO_ENGINE_CONTEXT engineContext = 
           (PWINBIO_ENGINE_CONTEXT)Pipeline->EngineContext;

    // Verify the state of the pipeline.
    if (engineContext == NULL ||
        engineContext->FileHandle == INVALID_HANDLE_VALUE)
    {
        hr = WINBIO_E_INVALID_DEVICE_STATE;
        goto cleanup;
    }

    switch (ControlCode)
    {
    case MY_NONPRIVILEGED_CTRL_CODE_NP1:
        {
            CTRL_CODE_NP1_SEND_BUFFER *sendBuffer = (CTRL_CODE_NP1_SEND_BUFFER*)SendBuffer;

            // Verify the size of the send buffer.
            if (SendBufferSize < sizeof(CTRL_CODE_NP1_SEND_BUFFER))
            {
                hr = E_INVALIDARG;
                break;
            }

            // Perform any other checks that may be required on the buffer 
            // contents. Return E_INVALIDARG if any of the checks fail.
            if (sendBuffer->SomeField != SomeSpecialValue ||
                sendBuffer->SomeOtherField != SomeOtherSpecialValue)
            {
                hr = E_INVALIDARG;
                break;
            }

            if (ReceiveBufferSize < sizeof(CTRL_CODE_NP1_RECEIVE_BUFFER))
            {
                hr = E_NOT_SUFFICIENT_BUFFER;
                break;
            }
        }

        // Fall through and perform the control operation after the switch
        // statement. Alternatively, depending on your requirements, you can 
        // perform the control operation here.
        break;

    case MY_NONPRIVILEGED_CTRL_CODE_NP2:
        // Continue testing for other non-privileged control codes that your
        // adapter supports.
        {
            CTRL_CODE_NP2_SEND_BUFFER *sendBuffer = (CTRL_CODE_NP2_SEND_BUFFER*)SendBuffer;

            // Verify the size of the send buffer.
            if (SendBufferSize < sizeof(CTRL_CODE_NP2_SEND_BUFFER))
            {
                hr = E_INVALIDARG;
                break;
            }

            // Perform any other checks that may be required on the buffer 
            // contents. Return E_INVALIDARG if any of the checks fail.
            if (sendBuffer->SomeField != SomeSpecialValue ||
                sendBuffer->SomeOtherField != SomeOtherSpecialValue)
            {
                hr = E_INVALIDARG;
                break;
            }

            if (ReceiveBufferSize < sizeof(CTRL_CODE_NP2_RECEIVE_BUFFER))
            {
                hr = E_NOT_SUFFICIENT_BUFFER;
                break;
            }
        }
        break;

    default:
        // All unrecognized control code values should return an error.
        hr = WINBIO_E_INVALID_CONTROL_CODE;
        break;
    }
    if (FAILED(hr))
    {
        goto cleanup;
    }

    // If control code validation succeeds, perform the control operation. This
    // example assumes that your adapter context structure contains an open
    // handle to a hardware driver. It also assumes that the driver performs
    // overlapped I/O and that a properly initialized OVERLAPPED structure is
    // contained in the engine context.
    result = DeviceIoControl(
                Pipeline->EngineHandle,
                ControlCode,
                SendBuffer,
                (DWORD)SendBufferSize,
                ReceiveBuffer,
                (DWORD)ReceiveBufferSize,
                (LPDWORD)ReceiveDataSize,
                &Pipeline->EngineContext->Overlapped
                );
    if (result == FALSE && GetLastError() == ERROR_IO_PENDING)
    {
        SetLastError(ERROR_SUCCESS);

        result = GetOverlappedResult(
                    Pipeline->EngineHandle,
                    &Pipeline->EngineContext->Overlapped,
                    (LPDWORD)ReceiveDataSize,
                    TRUE
                    );
    }
    *OperationStatus = GetLastError();

    if (!result)
    {
        hr = _AdapterGetHresultFromWin32(*OperationStatus);
    }

cleanup:

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