Edit

WinI3CRead function (wini3c.h)

Performs a read from a WinI3C-Target. This corresponds to an I3C Private Read.

WinI3CRead is a Library-managed WinI3C API (the recommended way to use WinI3C). For an overlapped equivalent that uses a client-supplied file handle, see WinI3CReadWithFileHandle.

Syntax

_Must_inspect_result_
HRESULT WINAPI WinI3CRead(
    _In_ WinI3CTarget target,
    _In_ WINI3C_TARGET_MODE readPreferredMode,
    _In_reads_opt_(1) const UINT8* readHdrCommandCode,
    _In_ UINT32 requestedReadPayloadSize,
    _Out_writes_bytes_to_(requestedReadPayloadSize, *actualReadPayloadSize) void* readPayload,
    _Deref_out_range_(0, requestedReadPayloadSize) UINT32* actualReadPayloadSize);

Parameters

[in] target

The WinI3CTarget to read from.

The handle shall have been created by WinI3CInitializeTarget.

[in] readPreferredMode

The preferred WINI3C_TARGET_MODE to use for the read. This is best-effort; the actual mode may differ if the WinI3C-Target/HostController-Instance does not support the requested mode.

[in, optional] readHdrCommandCode

If readPreferredMode is WinI3CTargetModeHdr, points to the I3C HDR Read Command Code (0x80–0xFF) to use if the transfer is sent as HDR.

Shall be NULL if readPreferredMode is not WinI3CTargetModeHdr.

[in] requestedReadPayloadSize

The number of bytes to read. The maximum read size expected by the WinI3C-Target is set with WinI3CSetMaxReadAndIbiLength.

  • Shall be > 0.
  • Shall be <= bufferSize(readPayload).
  • Shall be <= 65535 (the maximum I3C transfer size).
  • Shall be even (a multiple of 2) when readPreferredMode is WinI3CTargetModeHdr.

[out] readPayload

A client-allocated buffer that receives the read payload.

Shall not be NULL.

Valid only when the function returns S_OK.

[out] actualReadPayloadSize

Receives the actual number of bytes read.

This may be less than requestedReadPayloadSize, because a WinI3C-Target may respond with less payload than requested (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 Successfully read the payload. This does not imply that requestedReadPayloadSize bytes were read; see actualReadPayloadSize.
E_INVALIDARG One or more parameters are invalid.
E_OUTOFMEMORY Available memory is insufficient to execute this function.
HRESULT_FROM_WIN32(ERROR_DEVICE_NACKED) The WinI3C-Target (passively) NACKed, because it is busy or has experienced a fatal hardware error. The client may retry later; consider first calling WinI3CGetStatus.
HRESULT_FROM_WIN32(ERROR_DEVICE_NOT_CONNECTED) The WinI3C-Target is not connected. Destroy the handle with WinI3CRelease.
HRESULT_FROM_WIN32(ERROR_DEVICE_HARDWARE_ERROR) A fatal hardware error occurred. Destroy the handle with WinI3CRelease.

Remarks

The maximum read size expected by the WinI3C-Target is set with WinI3CSetMaxReadAndIbiLength.

This function is thread-safe.

Example

#include <wini3c.h>

void main()
{
    ...

    const uint32_t requestedReadPayloadSize = ...;
    uint8_t readPayload[requestedReadPayloadSize] = { 0 };
    uint32_t actualReadPayloadSize = 0;

    if (FAILED(WinI3CRead(
        target,
        WinI3CTargetModeSdr,
        nullptr,
        requestedReadPayloadSize,
        readPayload,
        &actualReadPayloadSize)))
    {
        // Handle failure.
    }

    ...
}

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

WinI3CWrite

WinI3CWriteRead

WinI3CSetMaxReadAndIbiLength

WINI3C_TARGET_MODE