You have not provided enough code for a firm answer. My best guess is you have a missing or extra curly brace eg. '{' or '}'.
C/C++ is case sensitive. You have the incorrect case for some functions and keywords. Look for "Printf", "createFile", and "Sizeof" for example.
If the source you've provided is in fact the entire source, your code needs to appear inside a main() function.
#include <windows.h>
int main(int argc, char *argv[])
{
HANDLE hSerial = CreateFile ("COM4",
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if( hSerial==INVALID_HANDLE_VALUE )
{
if(GetLastError()=ERROR_FILE_NOT_FOUND
{
printf("//SERIAL PORT DOES NOT EXIST// ");
}
printf("//SOME OTHER ERROR OCCURRED.//");
return 0;
}
DCB dcbSerialParams = {0};
dcbSerial.DCBlength = sizeof dcbSerialParams;
if ( !GetCommState(hSerial, &dcbSerialParams) )
{
printf("Error in getting state");
}
dcbSerialParams.BaudRate=CBR_9600;
dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits=ONESTOPBIT;
dcbSerialParams.Parity=NOPARITY;
if( !SetCommState(hSerial, &dcbSerialParams) )
{
printf("Error");
}
COMMTIMEOUTS timeouts={0};
timeouts.ReadIntervalTimeout=50;
timeouts.ReadTotalTimeoutConstant=50;
timeouts.ReadTotalTimeoutMultiplier=10;
timeouts.WriteTotalTimeoutConstant=50;
timeouts.WriteTotalTimeoutMultiplier=10;
if( !SetCommTimeouts(hSerial, &timeouts) )
{
printf("Error occurring in timeouts");
}
char szBuff[n + 1] = {0};
DWORD dwBytesRead = 0;
if( !ReadFile(hSerial, szBuff, n, &dwBytesRead, NULL) )
{
printf("Error occurred in read/write byte");
}
CloseHandle(hSerial);
return 0;
}
</windows.h>