From 08fd0bc1409a0a0d8679a6f0afb5169cd0a7d4e1 Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Wed, 19 Mar 2014 11:54:57 +1100 Subject: regsvr32-output --- programs/regsvr32/Makefile.in | 2 +- programs/regsvr32/regsvr32.c | 87 ++++++++++++++++++++++++++++++------------- programs/regsvr32/regsvr32.h | 34 +++++++++++++++++ programs/regsvr32/regsvr32.rc | 35 ++++++++++++++++- 4 files changed, 131 insertions(+), 27 deletions(-) create mode 100644 programs/regsvr32/regsvr32.h diff --git a/programs/regsvr32/Makefile.in b/programs/regsvr32/Makefile.in index b2c4e1b..db567ea 100644 --- a/programs/regsvr32/Makefile.in +++ b/programs/regsvr32/Makefile.in @@ -1,6 +1,6 @@ MODULE = regsvr32.exe APPMODE = -mconsole -IMPORTS = ole32 +IMPORTS = ole32 user32 C_SRCS = \ regsvr32.c diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c index 3536e93..0d5e2f9 100644 --- a/programs/regsvr32/regsvr32.c +++ b/programs/regsvr32/regsvr32.c @@ -51,10 +51,13 @@ #include "config.h" #include "wine/port.h" -#include #include #include #include +#include "regsvr32.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(regsvr32); typedef HRESULT (*DLLREGISTER) (void); typedef HRESULT (*DLLUNREGISTER) (void); @@ -62,16 +65,36 @@ typedef HRESULT (*DLLINSTALL) (BOOL,LPCWSTR); static BOOL Silent = FALSE; -static int Usage(void) +static void __cdecl output_write(UINT id, ...) { - printf("regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname ...\n"); - printf("\t[/u] unregister server\n"); - printf("\t[/s] silent (no message boxes)\n"); - printf("\t[/i] Call DllInstall passing it an optional [cmdline];\n"); - printf("\t when used with /u calls dll uninstall\n"); - printf("\t[/n] Do not call DllRegisterServer; this option " - "must be used with [/i]\n"); - return 0; + char fmt[1024]; + __ms_va_list va_args; + char *str; + DWORD len, nOut, ret; + + if (!LoadStringA(GetModuleHandleA(NULL), id, fmt, sizeof(fmt)/sizeof(fmt[0]))) + { + WINE_FIXME("LoadString failed with %d\n", GetLastError()); + return; + } + + __ms_va_start(va_args, id); + SetLastError(NO_ERROR); + len = FormatMessageA(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER, + fmt, 0, 0, (LPSTR)&str, 0, &va_args); + __ms_va_end(va_args); + if (len == 0 && GetLastError() != NO_ERROR) + { + WINE_FIXME("Could not format string: le=%u, fmt=%s\n", GetLastError(), wine_dbgstr_a(fmt)); + return; + } + + ret = WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), str, len, &nOut, NULL); + + if (!ret) + WINE_WARN("regsvr32: WriteConsoleA() failed.\n"); + + LocalFree(str); } /** @@ -90,7 +113,7 @@ static VOID *LoadProc(const char* strDll, const char* procName, HMODULE* DllHand if(!*DllHandle) { if(!Silent) - printf("Failed to load DLL %s\n", strDll); + output_write(STRING_DLL_LOAD_FAILED, strDll); ExitProcess(1); } @@ -98,7 +121,7 @@ static VOID *LoadProc(const char* strDll, const char* procName, HMODULE* DllHand if(!proc) { if(!Silent) - printf("%s not implemented in DLL %s\n", procName, strDll); + output_write(STRING_PROC_NOT_IMPLEMENTED, procName, strDll); FreeLibrary(*DllHandle); return NULL; } @@ -119,12 +142,12 @@ static int RegisterDll(const char* strDll) if(FAILED(hr)) { if(!Silent) - printf("Failed to register DLL %s\n", strDll); + output_write(STRING_REGISTER_FAILED, strDll); return -1; } if(!Silent) - printf("Successfully registered DLL %s\n", strDll); + output_write(STRING_REGISTER_SUCCESSFUL, strDll); if(DllHandle) FreeLibrary(DllHandle); @@ -145,12 +168,12 @@ static int UnregisterDll(char* strDll) if(FAILED(hr)) { if(!Silent) - printf("Failed to unregister DLL %s\n", strDll); + output_write(STRING_UNREGISTER_FAILED, strDll); return -1; } if(!Silent) - printf("Successfully unregistered DLL %s\n", strDll); + output_write(STRING_UNREGISTER_SUCCESSFUL, strDll); if(DllHandle) FreeLibrary(DllHandle); @@ -171,13 +194,21 @@ static int InstallDll(BOOL install, char *strDll, WCHAR *command_line) if(FAILED(hr)) { if(!Silent) - printf("Failed to %s DLL %s\n", install ? "install" : "uninstall", - strDll); + { + if (install) + output_write(STRING_INSTALL_FAILED, strDll); + else + output_write(STRING_UNINSTALL_FAILED, strDll); + } return -1; } if(!Silent) - printf("Successfully %s DLL %s\n", install ? "installed" : "uninstalled", - strDll); + { + if (install) + output_write(STRING_INSTALL_SUCCESSFUL, strDll); + else + output_write(STRING_UNINSTALL_SUCCESSFUL, strDll); + } if(DllHandle) FreeLibrary(DllHandle); @@ -197,7 +228,7 @@ int main(int argc, char* argv[]) OleInitialize(NULL); /* Strictly, the Microsoft version processes all the flags before - * the files (e.g. regsvr32 file1 /s file2 is silent even for file1. + * the files (e.g. regsvr32 file1 /s file2 is silent even for file1). * For ease, we will not replicate that and will process the arguments * in order. */ @@ -254,7 +285,11 @@ int main(int argc, char* argv[]) else if((!strcasecmp(argv[i], "/c"))||(!strcasecmp(argv[i], "-c"))) /* console output */; else if (argv[i][0] == '/' && (!argv[i][2] || argv[i][2] == ':')) - printf("Unrecognized switch %s\n", argv[i]); + { + output_write(STRING_UNRECOGNIZED_SWITCH, argv[i]); + output_write(STRING_USAGE); + return 1; + } else { char *DllName = argv[i]; @@ -286,9 +321,11 @@ int main(int argc, char* argv[]) if (!DllFound) { if(!Silent) - return Usage(); - else - return -1; + { + output_write(STRING_HEADER); + output_write(STRING_USAGE); + } + return 1; } OleUninitialize(); diff --git a/programs/regsvr32/regsvr32.h b/programs/regsvr32/regsvr32.h new file mode 100644 index 0000000..e3b50eb --- /dev/null +++ b/programs/regsvr32/regsvr32.h @@ -0,0 +1,34 @@ +/* + * Regsvr32 definitions + * + * Copyright 2014 Hugh McMaster + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* Resource strings */ +#define STRING_HEADER 1000 +#define STRING_USAGE 1001 +#define STRING_UNRECOGNIZED_SWITCH 1002 +#define STRING_DLL_LOAD_FAILED 1003 +#define STRING_PROC_NOT_IMPLEMENTED 1004 +#define STRING_REGISTER_FAILED 1005 +#define STRING_REGISTER_SUCCESSFUL 1006 +#define STRING_UNREGISTER_FAILED 1007 +#define STRING_UNREGISTER_SUCCESSFUL 1008 +#define STRING_INSTALL_FAILED 1009 +#define STRING_INSTALL_SUCCESSFUL 1010 +#define STRING_UNINSTALL_FAILED 1011 +#define STRING_UNINSTALL_SUCCESSFUL 1012 diff --git a/programs/regsvr32/regsvr32.rc b/programs/regsvr32/regsvr32.rc index c1ebe47..ba6d799 100644 --- a/programs/regsvr32/regsvr32.rc +++ b/programs/regsvr32/regsvr32.rc @@ -1,6 +1,7 @@ -/* Language neutral resources. +/* Regsvr32 resource strings * * Copyright 2003 Stefan Leichter + * Copyright 2014 Hugh McMaster * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,6 +18,38 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +#include +#include "regsvr32.h" + +#pragma makedep po + +LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT + +STRINGTABLE +{ + STRING_HEADER, "Wine DLL Registration Server\n\n\ +Provides DLL registration services.\n\n" + STRING_USAGE, "Usage:\n\ +\ regsvr32 [/u] [/s] [/n] [/i[:cmdline]] DllName\n\n\ +Options:\n\ +\ [/u] Unregister a module from the server.\n\ +\ [/s] Silent mode (no messages will be displayed).\n\ +\ [/i] Call DllInstall, passing an optional [cmdline].\n\ +\tWhen used with [/u], regsvr32 also calls DLL Uninstall.\n\ +\ [/n] Do not call DllRegisterServer. This option must be used with [/i].\n\n" + STRING_UNRECOGNIZED_SWITCH, "regsvr32: Invalid or unrecognized switch [%1]\n\n" + STRING_DLL_LOAD_FAILED, "regsvr32: Failed to load DLL '%1'\n" + STRING_PROC_NOT_IMPLEMENTED, "regsvr32: %1 not implemented in DLL '%2'\n" + STRING_REGISTER_FAILED, "regsvr32: Failed to register DLL '%1'\n" + STRING_REGISTER_SUCCESSFUL, "regsvr32: Successfully registered DLL '%1'\n" + STRING_UNREGISTER_FAILED, "regsvr32: Failed to unregister DLL '%1'\n" + STRING_UNREGISTER_SUCCESSFUL, "regsvr32: Successfully unregistered DLL '%1'\n" + STRING_INSTALL_FAILED, "regsvr32: Failed to install DLL '%1'\n" + STRING_INSTALL_SUCCESSFUL, "regsvr32: Successfully installed DLL '%1'\n" + STRING_UNINSTALL_FAILED, "regsvr32: Failed to uninstall DLL '%1'\n" + STRING_UNINSTALL_SUCCESSFUL, "regsvr32: Successfully uninstalled DLL '%1'\n" +} + #define WINE_FILEDESCRIPTION_STR "Wine Register Server" #define WINE_FILENAME_STR "REGSVR32" #define WINE_FILETYPE VFT_APP -- 1.8.3.2