From: Hugh McMaster Subject: [2/4] regsvr32: Convert to Unicode Message-Id: <9CB7F20010CADE479EB89B7DCEDFB642687E60AE61@VMBX112.ihostexchange.net> Date: Tue, 29 Apr 2014 02:03:24 -0400 This patch modifies the source in regsvr32.c so that regsvr32.exe runs entirely in Unicode. Two resource strings are also updated. This patch is the second of a series of four: 1. Implement new argument/flag handler. 2. Convert source to Unicode. 3. Add WriteFile() support if WriteConsoleW() fails. 4. Improve source comments (e.g. spelling, grammar, etc.) From f3034474c53a9efa4e260728521c97f34c8acc1a Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Mon, 28 Apr 2014 19:58:29 +1000 Subject: regsvr32-unicode --- programs/regsvr32/Makefile.in | 2 +- programs/regsvr32/regsvr32.c | 67 ++++++++++++++++++------------------------- programs/regsvr32/regsvr32.rc | 4 +-- 3 files changed, 31 insertions(+), 42 deletions(-) diff --git a/programs/regsvr32/Makefile.in b/programs/regsvr32/Makefile.in index db567ea..b99db28 100644 --- a/programs/regsvr32/Makefile.in +++ b/programs/regsvr32/Makefile.in @@ -1,5 +1,5 @@ MODULE = regsvr32.exe -APPMODE = -mconsole +APPMODE = -mconsole -municode IMPORTS = ole32 user32 C_SRCS = \ diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c index d2766a7..4d0ec0c 100644 --- a/programs/regsvr32/regsvr32.c +++ b/programs/regsvr32/regsvr32.c @@ -4,6 +4,7 @@ * Copyright 2001 ReactOS project * Copyright 2001 Jurgen Van Gael [jurgen.vangael@student.kuleuven.ac.be] * Copyright 2002 Andriy Palamarchuk + * 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 @@ -51,11 +52,10 @@ #include "config.h" #include "wine/port.h" -#include -#include #include #include #include "regsvr32.h" +#include "wine/unicode.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(regsvr32); @@ -68,14 +68,14 @@ static BOOL Silent = FALSE; static void __cdecl output_write(UINT id, ...) { - char fmt[1024]; + WCHAR fmt[1024]; __ms_va_list va_args; - char *str; + WCHAR *str; DWORD len, nOut, ret; if (Silent) return; - if (!LoadStringA(GetModuleHandleA(NULL), id, fmt, sizeof(fmt)/sizeof(fmt[0]))) + if (!LoadStringW(GetModuleHandleW(NULL), id, fmt, sizeof(fmt)/sizeof(fmt[0]))) { WINE_FIXME("LoadString failed with %d\n", GetLastError()); return; @@ -83,19 +83,19 @@ static void __cdecl output_write(UINT id, ...) __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); + len = FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER, + fmt, 0, 0, (LPWSTR)&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)); + WINE_FIXME("Could not format string: le=%u, fmt=%s\n", GetLastError(), wine_dbgstr_w(fmt)); return; } - ret = WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), str, len, &nOut, NULL); + ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, len, &nOut, NULL); if (!ret) - WINE_WARN("regsvr32: WriteConsoleA() failed.\n"); + WINE_WARN("regsvr32: WriteConsoleW() failed.\n"); LocalFree(str); } @@ -108,11 +108,11 @@ static void __cdecl output_write(UINT id, ...) * procName - name of the procedure to load from dll * pDllHanlde - output variable receives handle of the loaded dll. */ -static VOID *LoadProc(const char* strDll, const char* procName, HMODULE* DllHandle) +static VOID *LoadProc(const WCHAR *strDll, const char *procName, HMODULE *DllHandle) { VOID* (*proc)(void); - *DllHandle = LoadLibraryExA(strDll, 0, LOAD_WITH_ALTERED_SEARCH_PATH); + *DllHandle = LoadLibraryExW(strDll, 0, LOAD_WITH_ALTERED_SEARCH_PATH); if(!*DllHandle) { output_write(STRING_DLL_LOAD_FAILED, strDll); @@ -128,7 +128,7 @@ static VOID *LoadProc(const char* strDll, const char* procName, HMODULE* DllHand return proc; } -static int RegisterDll(const char* strDll) +static int RegisterDll(const WCHAR *strDll) { HRESULT hr; DLLREGISTER pfRegister; @@ -151,7 +151,7 @@ static int RegisterDll(const char* strDll) return 0; } -static int UnregisterDll(char* strDll) +static int UnregisterDll(WCHAR *strDll) { HRESULT hr; DLLUNREGISTER pfUnregister; @@ -174,7 +174,7 @@ static int UnregisterDll(char* strDll) return 0; } -static int InstallDll(BOOL install, char *strDll, WCHAR *command_line) +static int InstallDll(BOOL install, WCHAR *strDll, WCHAR *command_line) { HRESULT hr; DLLINSTALL pfInstall; @@ -203,14 +203,13 @@ static int InstallDll(BOOL install, char *strDll, WCHAR *command_line) return 0; } -static WCHAR *parse_cmdline(char *command_line) +static WCHAR *parse_cmdline(WCHAR *command_line) { static WCHAR EmptyLine[1] = {0}; - WCHAR *wsCommandLine = NULL; if (command_line[0] == ':' && command_line[1]) { - int len = strlen(command_line); + int len = lstrlenW(command_line); command_line++; len--; @@ -225,33 +224,23 @@ static WCHAR *parse_cmdline(char *command_line) command_line[len] = 0; } } - if (command_line[0]) - { - len = MultiByteToWideChar(CP_ACP, 0, command_line, -1, NULL, 0); - wsCommandLine = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); - if (wsCommandLine) - MultiByteToWideChar(CP_ACP, 0, command_line, -1, wsCommandLine, len); - } - else - { - wsCommandLine = EmptyLine; - } + if (!command_line[0]) + command_line = EmptyLine; } else - { - wsCommandLine = EmptyLine; - } - return wsCommandLine; + command_line = EmptyLine; + + return command_line; } -int main(int argc, char* argv[]) +int wmain(int argc, WCHAR *argv[]) { int i; BOOL CallRegister = TRUE; BOOL CallInstall = FALSE; BOOL Unregister = FALSE; BOOL DllFound = FALSE; - WCHAR* wsCommandLine = NULL; + WCHAR* command_line = NULL; OleInitialize(NULL); @@ -270,7 +259,7 @@ int main(int argc, char* argv[]) output_write(STRING_USAGE); return 1; } - switch (tolower(argv[i][1])) + switch (tolowerW(argv[i][1])) { case 'u': Unregister = TRUE; @@ -280,7 +269,7 @@ int main(int argc, char* argv[]) break; case 'i': CallInstall = TRUE; - wsCommandLine = parse_cmdline(argv[i] + strlen("/i")); + command_line = parse_cmdline(argv[i] + 2 /* strlen("/i") */); break; case 'n': CallRegister = FALSE; @@ -296,7 +285,7 @@ int main(int argc, char* argv[]) } else { - char *DllName = argv[i]; + WCHAR *DllName = argv[i]; int res = 0; DllFound = TRUE; @@ -314,7 +303,7 @@ int main(int argc, char* argv[]) if (CallInstall) { - res = InstallDll(!Unregister, DllName, wsCommandLine); + res = InstallDll(!Unregister, DllName, command_line); } if (res) diff --git a/programs/regsvr32/regsvr32.rc b/programs/regsvr32/regsvr32.rc index 9b951b1..53e7efd 100644 --- a/programs/regsvr32/regsvr32.rc +++ b/programs/regsvr32/regsvr32.rc @@ -35,11 +35,11 @@ Options:\n\ \ [/u] Unregister a server.\n\ \ [/s] Silent mode (no messages will be displayed).\n\ \ [/i] Call DllInstall, passing an optional [cmdline].\n\ -\tWhen used with [/u] DllInstall is called in uninstall mode.\n\ +\tWhen used with [/u], DllInstall is called in uninstall mode.\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_PROC_NOT_IMPLEMENTED, "regsvr32: '%1!S!' was not found 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" -- 1.8.3.2