Something like the following should get you started.
HANDLE com;
DCB state;
DWORD temp;
char buff[1024];
com = CreateFile("\\\\.\\COM10", // open COM10
CENERIC_READ|GENERIC_WRITE, // for reading and writing
0, // exclusively
NULL, // without security
OPEN_EXISTING, // don't re-create if not there
0, // regular, sequential access
NULL); // no template
if(INVALID_HANDLE_VALUE != com)
{
GetCommState(com, &state); // get current port settings
state.BaudRate = 9600;
state.ByteSize = 8;
state.Parity = NOPARITY;
state.StopBits = ONESTOPBIT;
SetCommState(com, &state); // set port settings to specified
// port is now setup and ready for communication
WriteFile(com, // port handle
"AT\r", // string to write, "\r" is CR
3, // number of bytes to write
&temp, // number of bytes written
NULL);
if(3 != temp)
{
// something happened and all the data wasn't written...
}
ReadFile(com, // port handle
buff, // buffer to hold read data
3, // number of bytes to read
&temp, // will be filled in with the number of bytes read
NULL);
// buff should now contain "OK\r"
// do something with read data...
CloseHandle(com); // close port
}
else // Unable to open COM port
{
// how do we deal with it?
}
That given, why are you using VC++? I would look into using C# for something like this since it’s easy to learn if you know C++ or Java, and is easier to write code like this in.