To receive data on the same PC you need a loopback plug on your serial port (without using hardware flow control this plug just connects the TXD line to the RXD line).
Use the Windows API function
CreateFile()
to open the port and
WriteFile()
/
ReadFile()
to write and read (untested example):
HANDLE hCom = ::CreateFile(_T("COM1"),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hCom != INVALID_HANDLE_VALUE)
{
DWORD dwWritten;
::WriteFile(hCom, "Test", strlen("Test"), &dwWritten, NULL);
DWORD dwRead;
char pBuf[32];
::ReadFile(hCom, pBuf, sizeof(pBuf), &dwRead, NULL);
pBuf[min(dwRead, sizeof(pBuf)-1)] = '\0';
::MessageBox(NULL, pBuf, _T("Received text"), MB_OK);
::CloseFile(hCom);
}