// aaaaaaaaaa.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <commdlg.h>
#define READ_TIMEOUT 500
#include <windef.h>
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR* currentuser = L"COM8";
LPCWSTR *lstr = (LPCWSTR *)(¤tuser);
HANDLE hComm;
DWORD dwRead;
OVERLAPPED osReader = {0};
DWORD dwRes;
hComm = CreateFile(*lstr,GENERIC_READ | GENERIC_WRITE, 0, 0,
OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);
if (hComm == INVALID_HANDLE_VALUE) printf("*Error opening port\n");
else printf("*Port opened succesfully\n");
osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (osReader.hEvent == NULL) printf("*Error creating overlapped event; abort\n");
BYTE inByte = 1;
for(int i=0; i<100; i++) {
if(!ReadFile(hComm, &inByte, 1, &dwRead, &osReader))
dwRes = WaitForSingleObject(osReader.hEvent, READ_TIMEOUT);
printf("%02x\n", inByte);
}
CloseHandle(osReader.hEvent);
//wait for user
int a;
scanf("%d", &a);
return 0;
}