title: Why does the interface always get stuck? MFC for the communication with serial port with MSComm
body: <p>I am working on a interface for communicating with serial port by using the MSComm ActiveX: get data from the sensor via serial port and display in the edit box in VS 2005.</p>
  
  <p>But every time when I run the program, after getting certain data (about 1~2 seconds), the program gets stuck, which I have to use task manager to stop. It seems that the buffer is full, but I have cleared the buffer using put_InBufferCount(0) (if I used it correctly). </p>
  
  <p>Another possible reason is the size of edit box SetLimitText(10000000000000000); But it doesnt work either. </p>
  
  <p>Many thanks in advance!</p>
  
  <p>Here is the code in OnCommMscomm1()</p>
  
  <pre><code>void CwtsDlg::OnCommMscomm1()
  {
      // TODO: Add your message handler code here
  
      VARIANT variant_inp;
      COleSafeArray safearray_inp;
      LONG len,k;
      BYTE rxdata[2048]; //An 8-bit integer that is not signed.
      CString strtemp;
  
  if(m_MSComm.get_CommEvent()==2) //2 means there is data in the buffer
      {
          CString m_strRe;
          variant_inp=m_MSComm.get_Input(); //Read buffer
          m_MSComm.put_InBufferCount(0);//clear the buffer
          safearray_inp=variant_inp; //ColeSafeArray Covert
          len=safearray_inp.GetOneDimSize(); //get safe data length
          for(k=0;k&lt;len;k++)
              safearray_inp.GetElement(&amp;k,rxdata+k);//convert to BYTE array
          for(k=0;k&lt;len;k++) //convert array to Cstring
          {
              BYTE bt=*(char*)(rxdata+k); //character
                  strtemp.Format(L"%02X ",bt); //put characters into temperary varibles with space
              m_strRe+=strtemp; //the data in this buffer
          }
          AppendLineToMultilineEditCtrl(m_editReceive,m_strRe);//append data to edit box
      }
  }
  </code></pre>