danperrin
June 14th, 2005, 02:39 AM
Can anyone explain why WM_GETTEXT works when using a stack buffer and fails when using a heap buffer. See code samples - this code has been simplified to demonstrate the problem.
//-- this works
#define MYLEN 255
char szText[MYLEN];
LRESULT lResult = ::SendMessage(hWndMyRichedit20A,WM_GETTEXT,MYLEN,(LPARAM)szText);
//-- this fails
DWORD dwLen = 255;
char * pszText = new char[dwLen];
ZeroMemory(pszText,dwLen);
LRESULT lResult = ::SendMessage(hWndMyRichedit20A,WM_GETTEXT,dwLen,(LPARAM)pszText);
if (lResult == 0)
TRACE("Last Error = %d\n",GetLastError());
delete [] pszText;
Note - both cases above work with standard text controls - the 2nd portion only ever fails with RichEdit controls.
- GetLastError() returns zero
- the RichEdit controls are owned by another process (hence the WM_GETTEXT and not GetWindowText(...))
Your comments would be appreciated. Thanks.
//-- this works
#define MYLEN 255
char szText[MYLEN];
LRESULT lResult = ::SendMessage(hWndMyRichedit20A,WM_GETTEXT,MYLEN,(LPARAM)szText);
//-- this fails
DWORD dwLen = 255;
char * pszText = new char[dwLen];
ZeroMemory(pszText,dwLen);
LRESULT lResult = ::SendMessage(hWndMyRichedit20A,WM_GETTEXT,dwLen,(LPARAM)pszText);
if (lResult == 0)
TRACE("Last Error = %d\n",GetLastError());
delete [] pszText;
Note - both cases above work with standard text controls - the 2nd portion only ever fails with RichEdit controls.
- GetLastError() returns zero
- the RichEdit controls are owned by another process (hence the WM_GETTEXT and not GetWindowText(...))
Your comments would be appreciated. Thanks.