I got this sample code from MSDN, But I got no idea how to convert the read byte as below:
PHP Code:DWORD PortReadThread (LPVOID lpvoid)
{
BYTE Byte;
wchar_t InBuff[1];
DWORD dwCommModemStatus, dwBytesTransferred;
// Specify a set of events to be monitored for the port.
SetCommMask (hPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RLSD | EV_RING);
while (hPort != INVALID_HANDLE_VALUE)
{
// Wait for an event to occur for the port.
WaitCommEvent (hPort, &dwCommModemStatus, 0);
// Re-specify the set of events to be monitored for the port.
SetCommMask (hPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RING);
if (dwCommModemStatus & EV_RXCHAR)
{
// Loop for waiting for the data.
do
{
// Read the data from the serial port.
ReadFile (hPort, &Byte, 1, &dwBytesTransferred, 0);
// Display the data read.
if (dwBytesTransferred == 1)
{
// How to convert the Byte to wchar_t buffer -> InBuff ??
// Help
}
} while (dwBytesTransferred == 1);
}
}
return 0;
}




Reply With Quote