Here is the full code, Comments starting with NOTE are the erroroneous... #include #include #include #include "resource.h" #include "convert.h" HWND hwndNextClipboardVierwer ; char * szInPageData ; HFONT hFont ; // Processes the conversion /* void ProcessConversion(HWND hDlg) { TCHAR * pInPageText = NULL ; TCHAR * pUnicodeText = NULL ; HWND hwndInPageText = GetDlgItem(hDlg, IDC_EDIT_INPAGE) ; HWND hwndUnicodeText = GetDlgItem(hDlg, IDC_EDIT_UNICODE) ; int iLen = GetWindowTextLength(hwndInPageText) ; if(iLen <=0) return ; pInPageText = new TCHAR[iLen + 1] ; GetWindowText(hwndInPageText, pInPageText, iLen) ; pUnicodeText = ConvertInPageToUncode(pInPageText, iLen) ; SetWindowText(hwndUnicodeText, pUnicodeText) ; if(pInPageText != NULL)delete []pInPageText ; if(pUnicodeText != NULL) delete []pUnicodeText ; } */ void DumpHex(TCHAR * szText, HWND hDlg) { int iLen = _tcsclen(szText) ; TCHAR szBuffer[10] ; /*NOTE: This call fails i.e. returns NULL (even iLen is > 0)*/ TCHAR * szHexDump = new TCHAR[iLen * 7] ; ZeroMemory(szHexDump, iLen * 7) ; for(int i = 0 ; i < iLen ; i++) { wsprintf(szBuffer, _T("0x%X, "), szText[i]) ; _tcscat(szHexDump, szBuffer) ; } SetDlgItemText(hDlg, IDC_EDIT_UNIHEX, szHexDump) ; /*NOTE: This Call generates Heap corruption message from CRT*/ delete [] szHexDump ; } BOOL CALLBACK DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { HANDLE hMemory = NULL; TCHAR * szUnicodeText = NULL ; char * lptstr = NULL ; int iLen = NULL ; switch(msg) { case WM_INITDIALOG: hwndNextClipboardVierwer = SetClipboardViewer(hWnd) ; hFont = CreateFont( 80, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _T("Pak Nastaleeq")) ; SendDlgItemMessage(hWnd, IDC_EDIT_UNICODE, WM_SETFONT, (WPARAM) hFont, TRUE) ; return FALSE ; // Handle the change of the clipboard. case WM_DRAWCLIPBOARD: if(OpenClipboard(hWnd)) { hMemory = GetClipboardData(CF_TEXT) ; lptstr = (char *) GlobalLock(hMemory) ; if(hMemory == NULL || lptstr == NULL) { CloseClipboard() ; return FALSE ; } iLen = strlen(lptstr) ; szInPageData = new char[iLen + 1] ; szUnicodeText = new TCHAR[(iLen / 2) + (iLen / 100) * 10] ; strcpy(szInPageData, lptstr) ; GlobalUnlock(hMemory) ; SendMessage(hwndNextClipboardVierwe