

GetWindowText( hwndOutput, pbuf, outLength ) Void AppendText( const HWND &hwnd, TCHAR *newText ) GetWindowText( hwndOutput, buf, outLength ) get existing text from edit control and put into buffer TCHAR * buf = ( TCHAR * ) GlobalAlloc( GPTR, outLength * sizeof(TCHAR) ) create buffer to hold current and new text Int outLength = GetWindowTextLength( hwndOutput ) + lstrlen(newText) + 1 get new length to determine buffer size HWND hwndOutput = GetDlgItem( hwnd, IDC_OUTPUT ) Try this: void AppendText( const HWND &hwnd, TCHAR *newText ) You are also leaking the memory that you allocate. You are also not allocating the buffer large enough to hold both the existing text and the new text being appended. If you are compiling for Unicode, TCHAR is 2 bytes, not 1 byte, but you are not taking that into account. GetWindowTextLength() returns the number of TCHAR elements in the text, but GlobalAlloc() expects a byte count instead.
