Hi all,
I'm new to eMbedded Visual C++ programming. Below is a program that my lecturer pass to me. But i don know why it cannot run correctly.

P/S : sorry, my english not so good.

Objective of this program : PDA display what was type on the Keyboard in an Edit Box.

Configuration : PDA download the program from COM port 1 using Active Sync.
After that, Connect PDA to COM port2, PDA display what i type on the keyboard.

Problem : PDA failed to display what i type.



// SENDDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SEND.h"
#include "SENDDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

DWORD numWrite;
int input;
HANDLE hSend;
BOOL err;
TCHAR pString[18];
CHAR *buffer = (CHAR*) malloc (sizeof(CHAR));


/////////////////////////////////////////////////////////////////////////////
// CSENDDlg dialog

CSENDDlg::CSENDDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSENDDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSENDDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSENDDlg:oDataExchange(CDataExchange* pDX)
{
CDialog:oDataExchange(pDX);
//{{AFX_DATA_MAP(CSENDDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP

DDX_Control (pDX, IDC_RX1, m_pString1);

}

BEGIN_MESSAGE_MAP(CSENDDlg, CDialog)
//{{AFX_MSG_MAP(CSENDDlg)
//}}AFX_MSG_MAP
ON_BN_CLICKED (IDC_BUTTON1, OnButton1)

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSENDDlg message handlers

BOOL CSENDDlg::OnInitDialog()
{
CDialog::OnInitDialog();

CString szPortName1;
DCB dcb;
COMMTIMEOUTS cto;


// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog


SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

CenterWindow(GetDesktopWindow()); // center to the hpc screen

//SetTimer(ID_CLOCK, 1000, NULL);

szPortName1 = "COM2:";

CloseHandle(hSend);

hSend = CreateFile (szPortName1, GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);

if (hSend == INVALID_HANDLE_VALUE)
{
MessageBox(TEXT("ERROR"));
}

else
{
GetCommState (hSend,&dcb);

dcb.BaudRate = CBR_9600;
dcb.fParity = FALSE;
dcb.fNull = FALSE;
dcb.StopBits = ONESTOPBIT;
dcb.Parity = NOPARITY;
dcb.ByteSize = 8;

SetCommState (hSend, &dcb);

// Set the timeouts. Set infinite read timeout.

cto.ReadIntervalTimeout = 0;
cto.ReadTotalTimeoutConstant = 0;
cto.ReadTotalTimeoutMultiplier = 0;
cto.WriteTotalTimeoutConstant = 1000;
cto.WriteTotalTimeoutMultiplier = 10;

SetCommTimeouts (hSend, &cto);
}

return TRUE; // return TRUE unless you set the focus to a control
}





void CSENDDlg::OnButton1()
{
DWORD numRead;
//CHAR szText1[1];
CHAR szText[6];

PurgeComm(hSend, PURGE_RXCLEAR);


while (1)
{
if (hSend != INVALID_HANDLE_VALUE)
{
ReadFile (hSend, szText, 1, &numRead, 0);

if (hSend == INVALID_HANDLE_VALUE)
{
MessageBox(TEXT("ERROR IN RECEIVING"));
}
else
{
input = szText[0];
HEX();
m_pString1.SetWindowText(pString);

}
}
}
}



void HEX()
{
int j,k;

j = (input & 0xFF) / 16;
_itoa (j,&buffer[0],16);

k = input & 0x00FF % 16;
_itoa(k,&buffer[1],16);

mbstowcs(pString,buffer,3);
}