[PATCH 2/7] regedit: Use FormatMessage() for optimal memory usage (v3)
Hugh McMaster
hugh.mcmaster at outlook.com
Wed Feb 1 06:56:27 CST 2017
Changes since v2:
*Use __ms_va_list, __ms_va_start and __ms_va_end.
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
programs/regedit/edit.c | 28 ++++++++++++++++------------
programs/regedit/regedit.rc | 12 ++++++------
2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/programs/regedit/edit.c b/programs/regedit/edit.c
index a223535..bafba3c 100644
--- a/programs/regedit/edit.c
+++ b/programs/regedit/edit.c
@@ -46,39 +46,43 @@ struct edit_params
LONG cbData;
};
-static INT vmessagebox(HWND hwnd, INT buttons, INT titleId, INT resId, va_list ap)
+static int vmessagebox(HWND hwnd, int buttons, int titleId, int resId, __ms_va_list va_args)
{
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, &va_args);
+ ret = MessageBoxW(hwnd, str, title, buttons);
+ LocalFree(str);
- return MessageBoxW(hwnd, errstr, title, buttons);
+ return ret;
}
static INT messagebox(HWND hwnd, INT buttons, INT titleId, INT resId, ...)
{
- va_list ap;
+ __ms_va_list ap;
INT result;
- va_start(ap, resId);
+ __ms_va_start(ap, resId);
result = vmessagebox(hwnd, buttons, titleId, resId, ap);
- va_end(ap);
+ __ms_va_end(ap);
return result;
}
void error(HWND hwnd, INT resId, ...)
{
- va_list ap;
+ __ms_va_list ap;
- va_start(ap, resId);
+ __ms_va_start(ap, resId);
vmessagebox(hwnd, MB_OK | MB_ICONERROR, IDS_ERROR, resId, ap);
- va_end(ap);
+ __ms_va_end(ap);
}
static void error_code_messagebox(HWND hwnd, DWORD error_code)
diff --git a/programs/regedit/regedit.rc b/programs/regedit/regedit.rc
index 072648e..51c4b11 100644
--- a/programs/regedit/regedit.rc
+++ b/programs/regedit/regedit.rc
@@ -176,16 +176,16 @@ END
STRINGTABLE
BEGIN
IDS_ERROR "Error"
- IDS_BAD_KEY "Can't query key '%s'"
- IDS_BAD_VALUE "Can't query value '%s'"
- IDS_UNSUPPORTED_TYPE "Can't edit keys of this type (%u)"
- IDS_TOO_BIG_VALUE "Value is too big (%u)"
+ IDS_BAD_KEY "Unable to query the registry key '%1'."
+ IDS_BAD_VALUE "Unable to query the registry value '%1'."
+ IDS_UNSUPPORTED_TYPE "Unable to edit registry keys of this type (%1!u!)."
+ IDS_TOO_BIG_VALUE "The value is too big (%1!u!)."
IDS_DELETE_BOX_TITLE "Confirm Value Delete"
- IDS_DELETE_BOX_TEXT "Are you sure you want to delete value '%s'?"
+ IDS_DELETE_BOX_TEXT "Are you sure you want to delete the registry value '%1'?"
IDS_DELETE_BOX_TEXT_MULTIPLE "Are you sure you want to delete these values?"
IDS_NEWKEY "New Key #%d"
IDS_NEWVALUE "New Value #%d"
- IDS_NOTFOUND "Search string '%s' not found"
+ IDS_NOTFOUND "The search string '%1' was not found."
END
STRINGTABLE
--
2.7.4
More information about the wine-patches
mailing list