From 059f42aa56fedd74e2bd17caaa763dd37282cbb4 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 29 May 2023 13:31:14 +0100 Subject: [PATCH] New Windows utility function: GetDlgItemTextW_alloc. Just like the existing GetDlgItemText_alloc, but for wide strings. --- windows/platform.h | 1 + windows/utils/getdlgitemtext_alloc.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/windows/platform.h b/windows/platform.h index d14ea50e..65b6308b 100644 --- a/windows/platform.h +++ b/windows/platform.h @@ -402,6 +402,7 @@ int message_box(HWND owner, LPCTSTR text, LPCTSTR caption, DWORD style, bool utf8, DWORD helpctxid); void MakeDlgItemBorderless(HWND parent, int id); char *GetDlgItemText_alloc(HWND hwnd, int id); +wchar_t *GetDlgItemTextW_alloc(HWND hwnd, int id); void split_into_argv(char *, bool includes_program_name, int *, char ***, char ***); diff --git a/windows/utils/getdlgitemtext_alloc.c b/windows/utils/getdlgitemtext_alloc.c index f0244d71..8db32901 100644 --- a/windows/utils/getdlgitemtext_alloc.c +++ b/windows/utils/getdlgitemtext_alloc.c @@ -1,7 +1,7 @@ /* - * Handy wrapper around GetDlgItemText which doesn't make you invent - * an arbitrary length limit on the output string. Returned string is - * dynamically allocated; caller must free. + * 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" @@ -18,3 +18,16 @@ char *GetDlgItemText_alloc(HWND hwnd, int id) 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; +}