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

Hugh McMaster hugh.mcmaster at outlook.com
Sun Jan 29 05:57:00 CST 2017


Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
 programs/regedit/edit.c     | 21 ++++++++++++++++-----
 programs/regedit/regedit.rc | 12 ++++++------
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/programs/regedit/edit.c b/programs/regedit/edit.c
index 80477e0..f6d6ed6 100644
--- a/programs/regedit/edit.c
+++ b/programs/regedit/edit.c
@@ -65,15 +65,26 @@ static void load_string(unsigned int msg_id, WCHAR *buf, unsigned int count)
 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];
+    DWORD len;
+    WCHAR *str;
+    int ret;
 
     load_string(titleId, title, COUNT_OF(title));
-    load_string(resId, errfmt, COUNT_OF(errfmt));
+    load_string(resId, fmt, COUNT_OF(fmt));
 
-    vsnprintfW(errstr, COUNT_OF(errstr), errfmt, ap);
+    SetLastError(NO_ERROR);
+    len = FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
+                         fmt, 0, 0, (WCHAR *)&str, 0, &ap);
+    if (len == 0 && GetLastError() != NO_ERROR)
+    {
+        WINE_FIXME("Could not format string: le=%u, fmt=%s\n", GetLastError(), wine_dbgstr_w(fmt));
+        return 0;
+    }
+    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, ...)
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