Edit

WinI3CWriteVendorCccWithFileHandle function (wini3c.h)

Initiates an overlapped write of the supplied Vendor Common Command Code (CCC) and optional payload to a WinI3C-Target. This corresponds to an I3C Direct Set CCC command.

WinI3CWriteVendorCccWithFileHandle is a Non-library-managed WinI3C API. It uses a client-supplied file handle and returns a WinI3CAsyncOperation for a client-managed overlapped operation. These APIs are intended only for advanced scenarios; this is generally not recommended. For most applications, use the library-managed WinI3CWriteVendorCcc instead.

Syntax

_Must_inspect_result_
HRESULT WINAPI WinI3CWriteVendorCccWithFileHandle(
    _In_ HANDLE targetFileHandle,
    _In_ UINT8 commandCode,
    _In_reads_opt_(1) const UINT8* definingByte,
    _When_(writeVendorCccPayload == NULL, _In_range_(0, 0)) UINT32 writeVendorCccPayloadSize,
    _In_reads_bytes_opt_(writeVendorCccPayloadSize) const void* writeVendorCccPayload,
    _In_ OVERLAPPED* writeVendorCccOverlapped,
    _Out_ WinI3CAsyncOperation* writeVendorCccOperation);

Parameters

[in] targetFileHandle

The file handle associated with the WinI3C-Target to write to.

The handle shall have been opened with FILE_FLAG_OVERLAPPED in the dwFlagsAndAttributes parameter of CreateFile.

[in] commandCode

The Write CCC to be sent.

Only Vendor Direct CCCs (0xE0–0xFE, inclusive) are permitted.

[in, optional] definingByte

An optional defining byte (secondary code) for the Vendor Direct CCC.

Specify NULL if none is supplied.

Not all WinI3C-Targets/HostController-Instances support defining bytes.

[in] writeVendorCccPayloadSize

The number of bytes to write.

  • Shall be 0 when writeVendorCccPayload is NULL.
  • Shall be <= bufferSize(writeVendorCccPayload).
  • Shall be <= 65535 (the maximum I3C transfer size).

[in, optional] writeVendorCccPayload

An optional client-allocated buffer containing the payload to write.

The buffer shall be writeVendorCccPayloadSize bytes.

Shall be NULL when writeVendorCccPayloadSize is 0.

The buffer shall not be destroyed until the overlapped operation has completed and writeVendorCccOperation has been released with WinI3CRelease.

[in] writeVendorCccOverlapped

A client-allocated OVERLAPPED to supply to the underlying overlapped I/O call.

[out] writeVendorCccOperation

Receives a library-created WinI3CAsyncOperation that represents this overlapped operation.

Valid only when the function returns S_OK.

Destroy it with WinI3CRelease after the operation completes and before destroying the associated OVERLAPPED.

Return value

On successfully initiating the operation, this function returns S_OK.

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

Return code Description
S_OK Successfully initiated the write. The WinI3C-Target may not have received the payload yet.
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_DEVICE_HARDWARE_ERROR) A fatal hardware error occurred. Close targetFileHandle with CloseHandle.

Remarks

Use the standard Win32 I/O APIs (e.g. GetOverlappedResult, CancelIo or an I/O completion port) to manage the overlapped operation.

Only Vendor Direct CCCs (0xE0–0xFE) are supported; broadcast and bus-management CCCs (e.g. ENEC/DEFGRPA) are not permitted.

CCCs are always sent at SDR, so a preferred mode cannot be specified.

When the overlapped operation has completed, destroy the library-created writeVendorCccOperation with WinI3CRelease (before destroying the associated OVERLAPPED).

This function is thread-safe.

Completion status

When the overlapped operation completes, its result (e.g. from GetOverlappedResult with HRESULT_FROM_WIN32(GetLastError())) is one of the following:

Completion code Description
S_OK Successfully wrote the Vendor CCC payload to the WinI3C-Target.
HRESULT_FROM_WIN32(ERROR_DEVICE_NACKED) The WinI3C-Target (passively) NACKed the write. Consider calling WinI3CGetStatusWithFileHandle to understand the current WinI3C-Target state.
HRESULT_FROM_WIN32(ERROR_DEVICE_HARDWARE_ERROR) A fatal hardware error occurred. Close targetFileHandle with CloseHandle.

Example

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

#include <wini3c.h>

int main()
{
    ...

    // Completion event.
    OVERLAPPED writeVendorCCCOverlapped{};
    writeVendorCCCOverlapped.hEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr);
    RETURN_LAST_ERROR_IF(writeVendorCCCOverlapped.hEvent == nullptr);

    auto closeEventOnExit = wil::scope_exit([&]()
    {
        CloseHandle(writeVendorCCCOverlapped.hEvent);
    });

    uint8_t directCCC = ...;
    std::vector<uint8_t> writePayload = ...;

    WinI3CAsyncOperation writeVendorCCCOperation;
    HRESULT writeVendorCccResult = WinI3CWriteVendorCccWithFileHandle(
        winI3cTargetHandle,
        directCCC,
        nullptr,
        (uint32_t)writePayload.size(),
        writePayload.data(),
        &writeVendorCCCOverlapped,
        &writeVendorCCCOperation);
    if (FAILED(writeVendorCccResult) && writeVendorCccResult != HRESULT_FROM_WIN32(ERROR_IO_PENDING))
    {
        // Error sending the VendorCCC.
        return writeVendorCccResult;
    }

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

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

    ...
}

Requirements

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

See also

WinI3CWriteVendorCcc

WinI3CReadVendorCccWithFileHandle

WinI3CRelease