Edit

WinI3CGetReadPayloadFromOperation function (wini3c.h)

Retrieves the payload (if any) associated with a completed overlapped operation started with:-

The underlying overlapped operation shall have completed before this function is called.

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

Syntax

_Must_inspect_result_
HRESULT WINAPI WinI3CGetReadPayloadFromOperation(
    _In_ HANDLE targetFileHandle,
    _In_ OVERLAPPED* readOverlapped,
    _In_ WinI3CAsyncOperation readOperation,
    _Outptr_result_bytebuffer_(*readPayloadSize) void** readPayload,
    _Out_ UINT32* readPayloadSize);

Parameters

[in] targetFileHandle

The file handle associated with the WinI3C-Target.

[in] readOverlapped

The client-allocated OVERLAPPED that was supplied to the originating read function.

[in] readOperation

The WinI3CAsyncOperation created by the originating read function.

[out] readPayload

Receives a pointer to a library-allocated buffer containing the read payload.

The buffer is readPayloadSize bytes and is destroyed when readOperation is released with WinI3CRelease.

Valid only when the function returns S_OK.

[out] readPayloadSize

Receives the actual number of bytes read. This may be less than the requested size, because a WinI3C-Target may respond with a short read.

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 the payload may be inspected. This does not imply the requested size was read.
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. 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.

Remarks

The retrieved readPayload is destroyed when readOperation is released with WinI3CRelease; copy it first if it is needed later.

For WinI3CWriteReadWithFileHandle, the read depends on the write succeeding first. If the write fails, the read is not issued and readPayloadSize is 0; if the write succeeds and the read fails, readPayloadSize is also 0. It is not possible to distinguish these two cases. If the distinction matters, issue separate WinI3CWriteWithFileHandle and WinI3CReadWithFileHandle calls.

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(readOperation);
    });

    // 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, &readOverlapped, &numberOfBytesTransferred, true))
    {
        RETURN_LAST_ERROR();
    }

    uint8_t* readPayload = nullptr;
    uint32_t actualReadPayloadSize;
    RETURN_IF_FAILED(WinI3CGetReadPayloadFromOperation(
        winI3cTargetHandle,
        &readOverlapped,
        readOperation,
        (void**)&readPayload,
        &actualReadPayloadSize));

    ...
}

Requirements

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

See also

WinI3CReadWithFileHandle

WinI3CWriteReadWithFileHandle

WinI3CReadVendorCccWithFileHandle

WinI3CPendIbiReadWithFileHandle

WinI3CRelease