Edit

WinI3CWrite function (wini3c.h)

Performs a blocking write of the supplied payload to a WinI3C-Target. This corresponds to an I3C Private Write.

WinI3CWrite is a Library-managed WinI3C API (the recommended way to use WinI3C). It operates on a WinI3CTarget handle and blocks until the write completes. For an overlapped equivalent that uses a client-supplied file handle, see WinI3CWriteWithFileHandle.

Syntax

_Must_inspect_result_
HRESULT WINAPI WinI3CWrite(
    _In_ WinI3CTarget target,
    _In_ WINI3C_TARGET_MODE writePreferredMode,
    _In_reads_opt_(1) const UINT8* writeHdrCommandCode,
    _In_ UINT32 writePayloadSize,
    _In_reads_bytes_(writePayloadSize) const void* writePayload);

Parameters

[in] target

The WinI3CTarget to write to.

The handle shall have been created by WinI3CInitializeTarget.

[in] writePreferredMode

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

[in, optional] writeHdrCommandCode

If writePreferredMode is WinI3CTargetModeHdr, points to the I3C HDR Write Command Code (0x00–0x7F) to use if the transfer is sent as HDR.

Shall be NULL if writePreferredMode is not WinI3CTargetModeHdr.

[in] writePayloadSize

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

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

[in] writePayload

A client-allocated buffer that contains the payload to write.

Shall not be NULL.

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 wrote the payload to the WinI3C-Target.
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 to validate that the WinI3C-Target is available.
HRESULT_FROM_WIN32(ERROR_DEVICE_NOT_CONNECTED) The WinI3C-Target is not connected. Subsequent I/O is not expected to succeed; destroy the handle with WinI3CRelease.
HRESULT_FROM_WIN32(ERROR_DEVICE_HARDWARE_ERROR) A fatal hardware error occurred. Subsequent I/O is not expected to succeed; destroy the handle with WinI3CRelease.

Remarks

The maximum write size expected by the WinI3C-Target is set with WinI3CSetMaxWriteLength.

This function is thread-safe.

Example

#include <vector>
#include <wini3c.h>

void main()
{
    ...

    std::vector<uint8_t> writePayload = { 0x01, 0x02, 0x03 };
    if (FAILED(WinI3CWrite(
        target,
        WinI3CTargetModeSdr,
        0,
        (uint32_t)writePayload.size(),
        writePayload.data())))
    {
        // 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

WinI3CWriteWithFileHandle

WinI3CRead

WinI3CWriteRead

WinI3CSetMaxWriteLength

WINI3C_TARGET_MODE