[PATCH v3 03/10] reg: Add system error printing function
Jonathan Vollebregt
jnvsor at gmail.com
Sat Nov 8 04:26:44 CST 2014
---
programs/reg/reg.c | 32 ++++++++++++++++++++++++++++----
programs/reg/reg.h | 1 +
programs/reg/reg.rc | 1 +
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index d299cbf..1ae5746 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -67,6 +67,30 @@ static int reg_message(int msg)
return reg_printfW(formatW, msg_buffer);
}
+static void reg_print_error(LSTATUS error_code)
+{
+ switch (error_code)
+ {
+ case ERROR_SUCCESS:
+ return;
+ case ERROR_BAD_COMMAND:
+ reg_message(STRING_INVALID_CMDLINE);
+ return;
+ default:
+ {
+ static const WCHAR error_string[] = {'%','0','5','d',':',' ','%','s',0};
+ WCHAR *message = NULL;
+ FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL,
+ error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (WCHAR *)&message, 0, NULL);
+
+ reg_message(STRING_ERROR);
+ reg_printfW(error_string, error_code, message);
+ LocalFree(message);
+ return;
+ }
+ }
+}
+
static HKEY get_rootkey(LPWSTR key)
{
static const WCHAR szHKLM[] = {'H','K','L','M',0};
@@ -397,7 +421,7 @@ int wmain(int argc, WCHAR *argvW[])
if (argc < 3)
{
- reg_message(STRING_INVALID_CMDLINE);
+ reg_print_error(ERROR_BAD_COMMAND);
return 1;
}
else if (argc == 3 && (!lstrcmpW(argvW[2], slashHelpW) ||
@@ -433,7 +457,7 @@ int wmain(int argc, WCHAR *argvW[])
if (argc < 3)
{
- reg_message(STRING_INVALID_CMDLINE);
+ reg_print_error(ERROR_BAD_COMMAND);
return 1;
}
else if (argc == 3 && (!lstrcmpW(argvW[2], slashHelpW) ||
@@ -464,7 +488,7 @@ int wmain(int argc, WCHAR *argvW[])
if (argc < 3)
{
- reg_message(STRING_INVALID_CMDLINE);
+ reg_print_error(ERROR_BAD_COMMAND);
return 1;
}
else if (argc == 3 && (!lstrcmpW(argvW[2], slashHelpW) ||
@@ -488,7 +512,7 @@ int wmain(int argc, WCHAR *argvW[])
}
else
{
- reg_message(STRING_INVALID_CMDLINE);
+ reg_print_error(ERROR_BAD_COMMAND);
return 1;
}
}
diff --git a/programs/reg/reg.h b/programs/reg/reg.h
index 2221647..1c2ae83 100644
--- a/programs/reg/reg.h
+++ b/programs/reg/reg.h
@@ -30,3 +30,4 @@
#define STRING_INVALID_CMDLINE 107
#define STRING_NO_REMOTE 108
#define STRING_CANNOT_FIND 109
+#define STRING_ERROR 110
diff --git a/programs/reg/reg.rc b/programs/reg/reg.rc
index 479912b..6183aaa 100644
--- a/programs/reg/reg.rc
+++ b/programs/reg/reg.rc
@@ -35,4 +35,5 @@ STRINGTABLE
STRING_INVALID_CMDLINE, "Error: Invalid command line parameters\n"
STRING_NO_REMOTE, "Error: Unable to add keys to remote machine\n"
STRING_CANNOT_FIND, "Error: The system was unable to find the specified registry key or value\n"
+ STRING_ERROR, "Unexpected error: "
}
--
2.1.3
More information about the wine-patches
mailing list