Firstly I cant test any code I write on COM1 as my port has no devices.........
I wrote the following using LPT1 (my paralell port that has a printer on it) so I guess they shouls work the same......Also of course I couldnt recieve data...only write.......but it should give you some idea..
Code:
#include <windows.h>
#include <string.h>
int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nShow)
{
HANDLE hFile;
DWORD dwWritten;
char Buff[] = "Hello World",
Feed[] = "\f";
hFile = CreateFile("LPT1",GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);//Open up LPT1
if(hFile == INVALID_HANDLE_VALUE){
MessageBox(HWND_DESKTOP,"Could not open LPT1",
"Error",MB_OK);
return 1;
}
WriteFile(hFile,Buff,strlen(Buff),&dwWritten,NULL);
//Write my catchy phrase
WriteFile(hFile,Feed,strlen(Feed),&dwWritten,NULL);
//Send the ASCII char to feed page
CloseHandle(hFile);//Close my handle
return 0;
}