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

PIBIO_SENSOR_CONTROL_UNIT_FN

コールバック

シグネチャ

HRESULT PIBIO_SENSOR_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 によって呼び出されます。特権の昇格を必要とするベンダー定義の制御操作を実行するには、SensorAdapterControlUnitPrivileged 関数を呼び出します。

戻り値

関数が成功すると 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)

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

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

例

次の擬似コードは、この関数の実装例の 1 つを示しています。この例はコンパイルできません。目的に合わせて調整する必要があります。

//////////////////////////////////////////////////////////////////////////////////////////
//
// SensorAdapterControlUnit
//
// 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 
//                            sensor adapter.
//      SendBufferSize      - Size, in bytes, of the buffer specified by the 
//                            SendBuffer parameter.
//      ReceiveBuffer       - Receives information returned by the sensor 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
SensorAdapterControlUnit(
    __inout PWINBIO_PIPELINE Pipeline,
    __in ULONG ControlCode,
    __in_bcount(SendBufferSize) PUCHAR SendBuffer,
    __in SIZE_T SendBufferSize,
    __in_bcount(ReceiveBufferSize) PUCHAR ReceiveBuffer,
    __in SIZE_T ReceiveBufferSize,
    __out SIZE_T *ReceiveDataSize,
    __out ULONG *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_SENSOR_CONTEXT sensorContext = 
                 (PWINBIO_SENSOR_CONTEXT)Pipeline->SensorContext;

    // Verify the state of the pipeline.
    if (sensorContext == NULL || 
        Pipeline->SensorHandle == 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 the driver performs overlapped I/O and that a properly 
    // initialized OVERLAPPED structure is contained in the sensor context.
    result = DeviceIoControl(
                Pipeline->SensorHandle,
                ControlCode,
                SendBuffer,
                (DWORD)SendBufferSize,
                ReceiveBuffer,
                (DWORD)ReceiveBufferSize,
                (LPDWORD)ReceiveDataSize,
                &sensorContext->Overlapped
                );
    if (result == FALSE && GetLastError() == ERROR_IO_PENDING)
    {
        SetLastError(ERROR_SUCCESS);

        result = GetOverlappedResult(
                    Pipeline->SensorHandle,
                    &sensorContext->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)