open the COM1 port

Dear sir,
 How can I open the COM1 port to read the characters  through it by using Visual C++ 5.0?
Thanks,
myleAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
galkinConnect With a Mentor Commented:
Com port is treated as file in Win32. So use CerateFile Win32 API function to open file and ReadFile and WriteFile to read/write data from/to port.

  HANDLE hPort = ::CreateFile
  ( _T("COM1"),
            GENERIC_READ | GENERIC_WRITE,
            0,    // exclusive access                
            NULL, // no security attributes
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            NULL  // No template
  );
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.