WM_GETTEXT help

Started by
1 comment, last by ELS1 22 years, 2 months ago
hmm...how come this doesnt work:
  
char* CButtonControl::GetText()
{
	char* buffer = NULL ;
	int length ;

	length = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0) ;
	SendMessage(hwnd, WM_GETTEXT, length, (LPARAM)buffer) ;

	return buffer ;

}
[source]  
Advertisement
From the documentation for WM_GETTEXT:

quote:
An application sends a WM_GETTEXT message to copy the text that corresponds to a window into a buffer provided by the caller.


The most important part to observe in the above is "a buffer provided by the caller"

You already get the length using GETTEXTLENGTH so you know how big to make the buffer, so just after that do something like:

buffer = new char[length];

and then remember to delete[] that buffer when the caller of your function has finished with it.


If CButtonControl inherits from any MFC classes, make sure that the hWnd is valid (use CWnd::GetSafeHwnd).

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

im writing my own API Wrappers

thanks for your help

This topic is closed to new replies.

Advertisement