由 Windows 生物特徵框架呼叫,執行廠商定義的控制操作,需要提升權限。 呼叫 EngineAdapterControlUnit 函式,執行廠商定義的控制操作,且不需提升權限。
語法
PIBIO_ENGINE_CONTROL_UNIT_PRIVILEGED_FN PibioEngineControlUnitPrivilegedFn;
HRESULT PibioEngineControlUnitPrivilegedFn(
[in, out] 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
)
{...}
參數
[in, out] Pipeline
指向與執行作業的生物特徵辨識單元相關聯的 WINBIO_PIPELINE 結構的指標。
[in] ControlCode
一個 ULONG 值,指定廠商定義的操作。
[in] SendBuffer
指標指向一個緩衝區,該緩衝區包含傳送給引擎適配器的控制資訊。 緩衝區的格式與內容由廠商定義。
[in] SendBufferSize
緩衝區的大小(以位元組為單位),由 SendBuffer 參數指定。
[in] ReceiveBuffer
指標指向一個緩衝區,該緩衝區接收引擎適配器回應控制操作回傳的資訊。 緩衝區的格式由廠商定義。
[in] ReceiveBufferSize
由 ReceiveBuffer 參數指定的緩衝區大小(以位元組為單位)。
[out] ReceiveDataSize
指標指向一個變數,該變數接收由 ReceiveBuffer 參數指定,寫入緩衝區的資料大小(以位元組為單位)。
[out] OperationStatus
指標指向一個變數,該變數接收廠商定義的狀態碼,該狀態碼指定控制操作的結果。
返回值
如果函式成功,則會傳回S_OK。 如果函式失敗,它必須傳回下列其中一個 HRESULT 值,以指出錯誤。
| 回傳碼 | Description |
|---|---|
|
必要指標引數為 NULL。 |
|
SendBuffer 參數指定的緩衝區大小或格式不正確,或 ControlCode 參數中指定的值未被介面卡辨識。 |
|
ReceiveBuffer 參數指定的緩衝區太小。 |
|
該行動被取消。 |
|
是硬體故障。 |
|
控制代碼參數中指定的值不會被介面卡識別。
便條 從 Windows 8 開始,請只使用 E_INVALIDARG 來標示此狀況。
|
備註
你對此函式的實作應與 EngineAdapterControlUnit 函式的實作相同,但執行 ControlCode 參數指定操作需要提升權限。 你負責定義操作範圍,並決定哪些需要更高的權限。
此函式必須檢查 ReceiveBufferSize 參數的值,以確保 ReceiveBuffer 參數指定的緩衝區足夠大以容納回傳的資料。
範例
下列虛擬程式碼顯示此函式的一種可能實作。 此範例不會編譯。 您必須調整它以適應您的目的。
///////////////////////////////////////////////////////////////////////////////
//
// EngineAdapterControlUnitPrivileged
//
// Purpose:
// Performs a vendor-defined control operation that requires 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
EngineAdapterControlUnitPrivileged(
__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_PRIVILEGED_CTRL_CODE_P1:
{
CTRL_CODE_P1_SEND_BUFFER *sendBuffer = (CTRL_CODE_P1_SEND_BUFFER*)SendBuffer;
// Verify the size of the send buffer.
if (SendBufferSize < sizeof(CTRL_CODE_P1_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_P1_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_PRIVILEGED_CTRL_CODE_P2:
// Continue testing for other privileged control codes that your
// adapter supports.
{
CTRL_CODE_P2_SEND_BUFFER *sendBuffer = (CTRL_CODE_P2_SEND_BUFFER*)SendBuffer;
// Verify the size of the send buffer.
if (SendBufferSize < sizeof(CTRL_CODE_P2_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_P2_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 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.
if (FAILED(hr))
{
goto cleanup;
}
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;
}
需求
| Requirement | 價值觀 |
|---|---|
| 最低支援的用戶端 | Windows 7 [僅限桌面應用程式] |
| 支援的最低伺服器 | Windows Server 2008 R2 [僅限傳統型應用程式] |
| 目標平臺 | 窗戶 |
| Header | winbio_adapter.h(包括Winbio_adapter.h) |