No, for the reasons pointed out by vart. In my example, the size of the array is 512, and GetWindowText will return a maximum of 512 characters, as indicated by the last argument.
If you need to return an unknown number of characters and therefore can not use a fixed size array, you can allocate memory dynamically. This function shows how to do that:
Code:
char* AllocAndGetText(HWND hwndControl)
{
int count = GetWindowTextLength(hwndControl);
char* result = malloc(count * sizeof(char));
if (result != NULL)
{
GetWindowText(hwndControl, result, count);
}
return result;
}
and the function would be used in the following manner:
Code:
char* edit_text = AllocAndGetText(hwndEdit);
/* Use text in edit_text */
/* Free memory when you're done with it. */
free(edit_text);
However, usually there is a reasonable maximum number of characters you would expect and you can use an array.
This
tutorial is very good if you haven't seen it.