Click here to Skip to main content
15,892,927 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: serial communication prog? Pin
Ștefan-Mihai MOGA26-Sep-06 22:51
professionalȘtefan-Mihai MOGA26-Sep-06 22:51 
QuestionMemory Allocation Pin
Polite Programmer26-Sep-06 20:10
Polite Programmer26-Sep-06 20:10 
AnswerRe: Memory Allocation Pin
Cedric Moonen26-Sep-06 20:10
Cedric Moonen26-Sep-06 20:10 
GeneralRe: Memory Allocation Pin
Polite Programmer26-Sep-06 20:22
Polite Programmer26-Sep-06 20:22 
GeneralRe: Memory Allocation Pin
Cedric Moonen26-Sep-06 20:28
Cedric Moonen26-Sep-06 20:28 
QuestionRe: Memory Allocation Pin
David Crow27-Sep-06 3:16
David Crow27-Sep-06 3:16 
AnswerRe: Memory Allocation Pin
User 21559726-Sep-06 20:26
User 21559726-Sep-06 20:26 
GeneralRe: Memory Allocation Pin
Polite Programmer26-Sep-06 20:31
Polite Programmer26-Sep-06 20:31 
Here is the full code, Comments starting with NOTE are the erroroneous...



<br />
#include <windows.h><br />
#include <tchar.h><br />
#include <stdio.h><br />
<br />
#include "resource.h"<br />
<br />
#include "convert.h"<br />
<br />
HWND hwndNextClipboardVierwer ;<br />
char * szInPageData ;<br />
HFONT hFont ;<br />
<br />
// Processes the conversion<br />
/*<br />
void ProcessConversion(HWND hDlg)<br />
{<br />
	TCHAR * pInPageText = NULL ;<br />
	TCHAR * pUnicodeText = NULL ;<br />
	HWND hwndInPageText = GetDlgItem(hDlg, IDC_EDIT_INPAGE) ;<br />
	HWND hwndUnicodeText = GetDlgItem(hDlg, IDC_EDIT_UNICODE) ;<br />
<br />
	int iLen = GetWindowTextLength(hwndInPageText) ;<br />
<br />
	if(iLen <=0) return ;<br />
<br />
	pInPageText = new TCHAR[iLen + 1] ;<br />
<br />
	GetWindowText(hwndInPageText, pInPageText, iLen) ;<br />
<br />
	pUnicodeText = ConvertInPageToUncode(pInPageText, iLen) ;<br />
	<br />
	SetWindowText(hwndUnicodeText, pUnicodeText) ;<br />
<br />
<br />
	if(pInPageText != NULL)delete []pInPageText ;<br />
	if(pUnicodeText != NULL) delete []pUnicodeText ;<br />
<br />
}<br />
*/<br />
<br />
<br />
void DumpHex(TCHAR * szText, HWND hDlg)<br />
{<br />
	int iLen = _tcsclen(szText) ;<br />
	TCHAR szBuffer[10] ;<br />
<br />
	/*NOTE: This call fails i.e. returns NULL (even iLen is > 0)*/<br />
	TCHAR * szHexDump = new TCHAR[iLen * 7] ;<br />
<br />
	ZeroMemory(szHexDump, iLen * 7) ;<br />
<br />
	for(int i = 0 ; i < iLen ; i++)<br />
	{<br />
		wsprintf(szBuffer, _T("0x%X, "), szText[i]) ;<br />
		_tcscat(szHexDump, szBuffer) ;<br />
	}<br />
<br />
	SetDlgItemText(hDlg, IDC_EDIT_UNIHEX, szHexDump) ;<br />
<br />
	/*NOTE: This Call generates Heap corruption message from CRT*/<br />
	delete [] szHexDump ;<br />
}<br />
<br />
BOOL CALLBACK DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)<br />
{<br />
	HANDLE hMemory = NULL;<br />
	TCHAR * szUnicodeText = NULL ;<br />
	char * lptstr = NULL ;<br />
	int iLen = NULL ;<br />
<br />
	switch(msg)<br />
	{<br />
	case WM_INITDIALOG:<br />
		<br />
		hwndNextClipboardVierwer = SetClipboardViewer(hWnd) ;<br />
		hFont = CreateFont( 80,<br />
							80,<br />
							0,<br />
							0,<br />
							0,<br />
							0,<br />
							0,<br />
							0,<br />
							0,<br />
							0,<br />
							0,<br />
							0,<br />
							0,<br />
							_T("Pak Nastaleeq")) ;<br />
		SendDlgItemMessage(hWnd, IDC_EDIT_UNICODE, WM_SETFONT, (WPARAM) hFont, TRUE) ;<br />
		return FALSE ;<br />
<br />
	// Handle the change of the clipboard.<br />
	case WM_DRAWCLIPBOARD:<br />
<br />
		if(OpenClipboard(hWnd))<br />
		{<br />
			hMemory = GetClipboardData(CF_TEXT) ;<br />
			lptstr = (char *) GlobalLock(hMemory) ;<br />
<br />
			if(hMemory == NULL || lptstr == NULL)<br />
			{<br />
				CloseClipboard() ;<br />
				return FALSE ;<br />
			}<br />
<br />
			iLen = strlen(lptstr) ;<br />
			szInPageData = new char[iLen + 1] ;<br />
			szUnicodeText = new TCHAR[(iLen / 2) + (iLen / 100) * 10] ;<br />
			strcpy(szInPageData, lptstr) ;<br />
			GlobalUnlock(hMemory) ;<br />
<br />
			SendMessage(hwndNextClipboardVierwer, msg, wParam, lParam) ;<br />
			ConvertInPageToUncode(szInPageData, iLen, szUnicodeText) ;<br />
			DumpHex(szUnicodeText, hWnd) ;<br />
			SetDlgItemText(hWnd, IDC_EDIT_UNICODE, szUnicodeText) ;<br />
<br />
			delete [] szInPageData ;<br />
			/*NOTE: Only this delete statement generates Heap corruption message from CRT*/<br />
			delete [] szUnicodeText ;<br />
<br />
			<br />
		}<br />
		<br />
<br />
		return TRUE ;<br />
<br />
	// Control Nofications<br />
	case WM_COMMAND:<br />
		switch(LOWORD(wParam))<br />
		{<br />
		case IDOK:<br />
			//ProcessConversion(hWnd) ;<br />
			EndDialog(hWnd, 1) ;<br />
			break ;<br />
		case IDCANCEL:<br />
			EndDialog(hWnd, 0) ;<br />
			break ;<br />
		<br />
		}<br />
		return TRUE ;<br />
<br />
	case WM_DESTROY:<br />
		ChangeClipboardChain(hWnd, hwndNextClipboardVierwer) ;<br />
		return TRUE ;<br />
	}<br />
<br />
	return FALSE ;<br />
}<br />
<br />
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,<br />
				   LPTSTR lpCmdLine, int nCmdShow)<br />
{<br />
	DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc) ;<br />
	return 0 ;<br />
}


Polite Programmer


More Object Oriented then C#

QuestionRe: Memory Allocation Pin
David Crow27-Sep-06 3:22
David Crow27-Sep-06 3:22 
GeneralRe: Memory Allocation Pin
nutkase27-Sep-06 18:35
nutkase27-Sep-06 18:35 
AnswerRe: Memory Allocation Pin
kakan26-Sep-06 20:33
professionalkakan26-Sep-06 20:33 
GeneralRe: Memory Allocation Pin
Polite Programmer26-Sep-06 20:41
Polite Programmer26-Sep-06 20:41 
GeneralRe: Memory Allocation [modified] Pin
kakan26-Sep-06 20:51
professionalkakan26-Sep-06 20:51 
Questionhow to refresh automatically in a property page? Pin
yijia_2426-Sep-06 20:04
yijia_2426-Sep-06 20:04 
QuestionRe: how to refresh automatically in a property page? Pin
David Crow27-Sep-06 3:25
David Crow27-Sep-06 3:25 
AnswerRe: how to refresh automatically in a property page? Pin
yijia_2427-Sep-06 15:47
yijia_2427-Sep-06 15:47 
QuestionRe: how to refresh automatically in a property page? Pin
David Crow28-Sep-06 2:37
David Crow28-Sep-06 2:37 
QuestionRe: how to refresh automatically in a property page? Pin
yijia_242-Oct-06 18:03
yijia_242-Oct-06 18:03 
AnswerRe: how to refresh automatically in a property page? Pin
David Crow3-Oct-06 2:49
David Crow3-Oct-06 2:49 
QuestionResucing the flickerring rate Pin
Pratheep Kenny26-Sep-06 19:08
Pratheep Kenny26-Sep-06 19:08 
AnswerRe: Resucing the flickerring rate Pin
kakan26-Sep-06 19:30
professionalkakan26-Sep-06 19:30 
Questionvcl in borlands c++ to be used in vc++ Pin
zareee26-Sep-06 18:45
zareee26-Sep-06 18:45 
AnswerRe: vcl in borlands c++ to be used in vc++ Pin
Christian Graus26-Sep-06 18:54
protectorChristian Graus26-Sep-06 18:54 
GeneralRe: vcl in borlands c++ to be used in vc++ Pin
zareee26-Sep-06 19:11
zareee26-Sep-06 19:11 
GeneralRe: vcl in borlands c++ to be used in vc++ Pin
Christian Graus26-Sep-06 19:39
protectorChristian Graus26-Sep-06 19:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.