title: c++ cant transfer data through com port when hyperterminal is connected
body: <p>I am trying to make RS-232 communication between the PC and the PC MCU PIC. So I started making the PC program first in C++, and it was errorless, and according to the <code>cout</code> I made to output the status it should be working, but I wanted to be sure. So I downloaded Hyperterminal and connected Tx to Rx pin in serial com port, but whenever I try to connect the hyperterminal it gives an error, saying <code>access denied (error 5)</code> when I try to run my C++ program. I don't understand where the problem really is. Here's the full code, if the problem was the code's, just to make sure:</p>
  
  <p>main.c:</p>
  
  <pre><code>        #include &lt;windows.h&gt;
          #include &lt;winbase.h&gt;
          #include &lt;iostream&gt;
  
          PDWORD sent;
          char buf;
  
          int main(){
  
          DCB serial;
  
          HANDLE hserial = CreateFile("\\\\.\\COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  
          serial.DCBlength = sizeof(DCB);
          serial.BaudRate = CBR_9600;
          serial.fBinary = true;
          serial.fParity = false;
          serial.ByteSize = 8;
          serial.Parity = NOPARITY;
          serial.StopBits =  ONESTOPBIT;
  
          char result = BuildCommDCB("baud=9600 parity=N data=8 stop=1", &amp;serial);
  
          if(result != 0){
              std::cout &lt;&lt; "DCB Structure Successfully Created!" &lt;&lt; std::endl;
          }else{
              std::cout &lt;&lt; "DCB Structure Creation Failed!" &lt;&lt; std::endl;
          }
  
          if(hserial != INVALID_HANDLE_VALUE){
              std::cout &lt;&lt; "COM Port Handle Successfully Created!" &lt;&lt; std::endl;
  
          }else{
              std::cout &lt;&lt; "COM Port Handle Creation Failed!" &lt;&lt; std::endl;
              std::cout &lt;&lt; GetLastError() &lt;&lt; std::endl;
          }
  
          char res = WriteFile(hserial, "0xFF", 1, sent, NULL);
  
          if(res != 0){
              std::cout &lt;&lt; "Writing to COM Port Successfull!" &lt;&lt; std::endl;
          }else{
              std::cout &lt;&lt; "Writing to COM Port Failed!" &lt;&lt; std::endl;
              std::cout &lt;&lt; GetLastError() &lt;&lt; std::endl;
          }
  
          CloseHandle(&amp;hserial);
  
          return 0;
  
          }
  </code></pre>