[PATCH 2/7] regedit: Use FormatMessage() for optimal memory usage (v2)

Alexandre Julliard julliard at winehq.org
Wed Feb 1 04:44:01 CST 2017


Hugh McMaster <hugh.mcmaster at outlook.com> writes:

> Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
> ---
>  programs/regedit/edit.c     | 14 +++++++++-----
>  programs/regedit/regedit.rc | 12 ++++++------
>  2 files changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/programs/regedit/edit.c b/programs/regedit/edit.c
> index a223535..3f2b7a4 100644
> --- a/programs/regedit/edit.c
> +++ b/programs/regedit/edit.c
> @@ -49,15 +49,19 @@ struct edit_params
>  static INT vmessagebox(HWND hwnd, INT buttons, INT titleId, INT resId, va_list ap)
>  {
>      WCHAR title[256];
> -    WCHAR errfmt[1024];
> -    WCHAR errstr[1024];
> +    WCHAR fmt[1024];
> +    WCHAR *str;
> +    int ret;
>  
>      LoadStringW(hInst, titleId, title, COUNT_OF(title));
> -    LoadStringW(hInst, resId, errfmt, COUNT_OF(errfmt));
> +    LoadStringW(hInst, resId, fmt, COUNT_OF(fmt));
>  
> -    vsnprintfW(errstr, COUNT_OF(errstr), errfmt, ap);
> +    FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
> +                   fmt, 0, 0, (WCHAR *)&str, 0, &ap);
> +    ret = MessageBoxW(hwnd, str, title, buttons);
> +    LocalFree(str);
>  
> -    return MessageBoxW(hwnd, errstr, title, buttons);
> +    return ret;
>  }

You have to use __ms_va_list with FormatMessage. Check how this is done
in regedit.c.

-- 
Alexandre Julliard
julliard at winehq.org



More information about the wine-devel mailing list