The WriteFile function transfers data through the serial connection to another device. Before calling this function, an application must open and configure a serial port.
Because Windows CE does not support overlapped I/O—also called asynchronous I/O—the primary thread or any thread that creates a window should not try to write a large amount of data to a serial port. Such threads are blocked and cannot manage message queues. An application can simulate overlapped I/O by creating multiple threads to handle read/write operations. To coordinate threads, an application calls the WaitCommEvent function to block threads until specific communication events occur. For more information about communication events, see Using Communication Events.
The following code example shows how to transfer data using the WriteFile function.
DWORD dwError,
dwNumBytesWritten;
WriteFile (hPort, // Port handle
&Byte, // Pointer to the data to write
1, // Number of bytes to write
&dwNumBytesWritten, // Pointer to the number of bytes
// written
NULL // Must be NULL for Windows CE
);