From: Hugh McMaster Subject: regsvr32: Convert to Unicode (try 4) Message-Id: <9CB7F20010CADE479EB89B7DCEDFB642687E3C3BA3@VMBX112.ihostexchange.net> Date: Fri, 11 Apr 2014 00:02:25 -0400 This patch converts the source in programs/regsvr32/regsvr32.c to Unicode and updates a few resource strings for greater clarity. As before, the fall-back to WriteFile is included in the accompanying patch. Changes from previous versions: - fixed a typo [GetModuleHandleA() should have been GetModuleHandleW()] - restored and modified a FIXME comment about a wWinMain entry point From 34065258b55914bb90aed0028c1f42592d946320 Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Fri, 11 Apr 2014 13:05:25 +1000 Subject: regsvr32-unicode-v4 --- programs/regsvr32/Makefile.in | 2 +- programs/regsvr32/regsvr32.c | 85 +++++++++++++++++++++---------------------- programs/regsvr32/regsvr32.h | 2 +- programs/regsvr32/regsvr32.rc | 7 ++-- 4 files changed, 48 insertions(+), 48 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 624acd6..c0f2851 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 @@ -40,10 +41,7 @@ */ /** - * FIXME - currently receives command-line parameters in ASCII only and later - * converts to Unicode. Ideally the function should have wWinMain entry point - * and then work in Unicode only, but it seems Wine does not have necessary - * support. + * FIXME - Ideally the application should have a wWinMain entry point. */ #define WIN32_LEAN_AND_MEAN @@ -51,10 +49,10 @@ #include "config.h" #include "wine/port.h" -#include #include #include #include "regsvr32.h" +#include "wine/unicode.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(regsvr32); @@ -67,14 +65,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; @@ -82,19 +80,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); } @@ -107,11 +105,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); @@ -120,14 +118,14 @@ static VOID *LoadProc(const char* strDll, const char* procName, HMODULE* DllHand proc = (VOID *) GetProcAddress(*DllHandle, procName); if(!proc) { - output_write(STRING_PROC_NOT_IMPLEMENTED, procName, strDll); + output_write(STRING_GETPROCADDRESS_FAILED, procName, strDll); FreeLibrary(*DllHandle); return NULL; } return proc; } -static int RegisterDll(const char* strDll) +static int RegisterDll(const WCHAR *strDll) { HRESULT hr; DLLREGISTER pfRegister; @@ -150,7 +148,7 @@ static int RegisterDll(const char* strDll) return 0; } -static int UnregisterDll(char* strDll) +static int UnregisterDll(WCHAR *strDll) { HRESULT hr; DLLUNREGISTER pfUnregister; @@ -173,7 +171,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; @@ -202,15 +200,25 @@ static int InstallDll(BOOL install, char *strDll, WCHAR *command_line) return 0; } -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; WCHAR EmptyLine[1] = {0}; + const WCHAR slashUW[] = {'/','u',0}; + const WCHAR hyphenUW[] = {'-','u',0}; + const WCHAR slashSW[] = {'/','s',0}; + const WCHAR hyphenSW[] = {'-','s',0}; + const WCHAR slashIW[] = {'/','i',0}; + const WCHAR hyphenIW[] = {'-','i',0}; + const WCHAR slashNW[] = {'/','n',0}; + const WCHAR hyphenNW[] = {'-','n',0}; + const WCHAR slashCW[] = {'/','c',0}; + const WCHAR hyphenCW[] = {'-','c',0}; OleInitialize(NULL); @@ -221,18 +229,19 @@ int main(int argc, char* argv[]) */ for(i = 1; i < argc; i++) { - if ((!strcasecmp(argv[i], "/u")) ||(!strcasecmp(argv[i], "-u"))) + if (!lstrcmpiW(argv[i], slashUW) || !lstrcmpiW(argv[i], hyphenUW)) Unregister = TRUE; - else if ((!strcasecmp(argv[i], "/s"))||(!strcasecmp(argv[i], "-s"))) + else if (!lstrcmpiW(argv[i], slashSW) || !lstrcmpiW(argv[i], hyphenSW)) Silent = TRUE; - else if ((!strncasecmp(argv[i], "/i", strlen("/i")))||(!strncasecmp(argv[i], "-i", strlen("-i")))) + else if (!strncmpiW(argv[i], slashIW, lstrlenW(slashIW)) || + !strncmpiW(argv[i], hyphenIW, lstrlenW(hyphenIW))) { - CHAR* command_line = argv[i] + strlen("/i"); + command_line = argv[i] + lstrlenW(slashIW); CallInstall = TRUE; if (command_line[0] == ':' && command_line[1]) { - int len = strlen(command_line); + int len = lstrlenW(command_line); command_line++; len--; @@ -247,29 +256,19 @@ int main(int argc, char* argv[]) command_line[len] = 0; } } - if (command_line[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; + command_line = EmptyLine; } } else { - wsCommandLine = EmptyLine; + command_line = EmptyLine; } } - else if((!strcasecmp(argv[i], "/n"))||(!strcasecmp(argv[i], "-n"))) + else if (!lstrcmpiW(argv[i], slashNW) || !lstrcmpiW(argv[i], hyphenNW)) CallRegister = FALSE; - else if((!strcasecmp(argv[i], "/c"))||(!strcasecmp(argv[i], "-c"))) + else if (!lstrcmpiW(argv[i], slashCW) || !lstrcmpiW(argv[i], hyphenCW)) /* console output */; else if (argv[i][0] == '/' && (!argv[i][2] || argv[i][2] == ':')) { @@ -279,7 +278,7 @@ int main(int argc, char* argv[]) } else { - char *DllName = argv[i]; + WCHAR *DllName = argv[i]; int res = 0; DllFound = TRUE; @@ -297,7 +296,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.h b/programs/regsvr32/regsvr32.h index e3b50eb..c9074d1 100644 --- a/programs/regsvr32/regsvr32.h +++ b/programs/regsvr32/regsvr32.h @@ -23,7 +23,7 @@ #define STRING_USAGE 1001 #define STRING_UNRECOGNIZED_SWITCH 1002 #define STRING_DLL_LOAD_FAILED 1003 -#define STRING_PROC_NOT_IMPLEMENTED 1004 +#define STRING_GETPROCADDRESS_FAILED 1004 #define STRING_REGISTER_FAILED 1005 #define STRING_REGISTER_SUCCESSFUL 1006 #define STRING_UNREGISTER_FAILED 1007 diff --git a/programs/regsvr32/regsvr32.rc b/programs/regsvr32/regsvr32.rc index 9b951b1..143cfa9 100644 --- a/programs/regsvr32/regsvr32.rc +++ b/programs/regsvr32/regsvr32.rc @@ -1,4 +1,5 @@ -/* Regsvr32 resource strings +/* + * Regsvr32 resource strings * * Copyright 2003 Stefan Leichter * Copyright 2014 Hugh McMaster @@ -35,11 +36,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_GETPROCADDRESS_FAILED, "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