1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 09:27:59 +00:00
putty-source/windows/utils/getdlgitemtext_alloc.c
Simon Tatham 059f42aa56 New Windows utility function: GetDlgItemTextW_alloc.
Just like the existing GetDlgItemText_alloc, but for wide strings.
2023-05-29 15:31:43 +01:00

34 lines
723 B
C

/*
* Handy wrappers around GetDlgItemText (A and W) which don't make you
* invent an arbitrary length limit on the output string. Returned
* string is dynamically allocated; caller must free.
*/
#include "putty.h"
char *GetDlgItemText_alloc(HWND hwnd, int id)
{
char *ret = NULL;
size_t size = 0;
do {
sgrowarray_nm(ret, size, size);
GetDlgItemText(hwnd, id, ret, size);
} while (!memchr(ret, '\0', size-1));
return ret;
}
wchar_t *GetDlgItemTextW_alloc(HWND hwnd, int id)
{
wchar_t *ret = NULL;
size_t size = 0;
do {
sgrowarray_nm(ret, size, size);
GetDlgItemTextW(hwnd, id, ret, size);
} while (!memchr(ret, '\0', size-1));
return ret;
}