Edit

WinI3CGetMaxWriteLengthFromOperation function (wini3c.h)

Retrieves the maximum write length (MWL) as determined by a WinI3C-Target, from a completed overlapped operation started with WinI3CSetMaxWriteLengthWithFileHandle. The underlying overlapped operation shall have completed before this function is called.

WinI3CGetMaxWriteLengthFromOperation is a Non-library-managed WinI3C API, intended only for advanced scenarios and generally not recommended.

Syntax

_Must_inspect_result_
HRESULT WINAPI WinI3CGetMaxWriteLengthFromOperation(
    _In_ HANDLE targetFileHandle,
    _In_ OVERLAPPED* setMwlOverlapped,
    _In_ WinI3CAsyncOperation setMwlOperation,
    _Out_ UINT16* actualMaxWriteLength);

Parameters

[in] targetFileHandle

The file handle associated with the WinI3C-Target.

[in] setMwlOverlapped

The client-allocated OVERLAPPED that was supplied to WinI3CSetMaxWriteLengthWithFileHandle.

[in] setMwlOperation

The WinI3CAsyncOperation created by WinI3CSetMaxWriteLengthWithFileHandle.

[out] actualMaxWriteLength

Receives the actual maximum write payload size, as determined by the WinI3C-Target, which may differ from the requested value.

Valid only when the function returns S_OK.

Return value

On success this function returns S_OK.

On failure this function returns an appropriate HRESULT error code, including the following.

Return code Description
S_OK The overlapped operation completed and actualMaxWriteLength may be inspected.
E_INVALIDARG One or more parameters are invalid.
E_OUTOFMEMORY Available memory is insufficient to execute this function.
HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE) targetFileHandle is invalid, or was not opened with FILE_FLAG_OVERLAPPED.
HRESULT_FROM_WIN32(ERROR_IO_PENDING) The overlapped operation has not completed.
HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) The overlapped operation returned more data than expected.
HRESULT_FROM_WIN32(ERROR_DEVICE_NACKED) The WinI3C-Target (passively) NACKed the SETMRL or GETMRL CCC. This can be because the WinI3C-Target is busy, doesn't support the CCC or has experienced a fatal hardware-error. Client may retry later (by invoking another read); consider first invoking WinI3CGetStatusWithFileHandle to validate the WinI3C-Target is available.
HRESULT_FROM_WIN32(ERROR_DEVICE_HARDWARE_ERROR) A fatal hardware error occurred. Close targetFileHandle with CloseHandle.

Remarks

The library-created setMwlOperation shall now be destroyed with WinI3CRelease.

This function is thread-safe.

Example

#include <wil\result.h>
#include <wil\resource.h>

#include <wini3c.h>

int main()
{
    ...

    auto destroyOperationOnExit = wil::scope_exit([&]()
    {
        WinI3CRelease(setMwlOperation);
    });

    // Blocking, waiting for result (for demonstration purposes only).
    // In a real application, would use a completion port or other async mechanism to avoid blocking the thread.
    DWORD numberOfBytesTransferred;
    if (!GetOverlappedResult(winI3cTargetHandle, &setMwlOverlapped, &numberOfBytesTransferred, true))
    {
        RETURN_LAST_ERROR();
    }

    uint16_t actualMaxWriteLength;
    RETURN_IF_FAILED(WinI3CGetMaxWriteLengthFromOperation(
        winI3cTargetHandle,
        &setMwlOverlapped,
        setMwlOperation,
        &actualMaxWriteLength));

    ...
}

Requirements

Requirement Value
Minimum supported client Windows 11 25H2 October update (build 26200)
Target Platform Windows
Header wini3c.h
DLL wini3c.dll

See also

WinI3CSetMaxWriteLengthWithFileHandle

WinI3CSetMaxWriteLength

WinI3CRelease