From: Hugh McMaster Subject: [4/4] regsvr32: Convert C source to Unicode Message-Id: <9CB7F20010CADE479EB89B7DCEDFB6426807962EC3@VMBX112.ihostexchange.net> Date: Mon, 10 Mar 2014 22:29:20 -0400 This patch converts the C source for regsvr32 to Unicode. Together, this patch series fixes bug 28189 by replacing printf calls with WriteConsoleW functionality. This enables all output to appear in wineconsole or, if running 'wine regsvr32.exe', in an xterm or equivalent. From 89dddc8ec8df39399f8491613941c71a7579fa07 Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Mon, 10 Mar 2014 22:48:04 +1100 Subject: Convert regsvr32 to unicode --- programs/regsvr32/Makefile.in | 2 +- programs/regsvr32/regsvr32.c | 79 +++++++++++++++++++++---------------------- 2 files changed, 39 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 4ec7a9e..196d536 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 @@ -39,13 +40,6 @@ * assume that anything longer than /. is a filename. */ -/** - * 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. - */ - #define WIN32_LEAN_AND_MEAN #include "config.h" @@ -54,6 +48,7 @@ #include #include #include "regsvr32.h" +#include "wine/unicode.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(regsvr32); @@ -122,11 +117,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); @@ -142,7 +137,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; @@ -165,7 +160,7 @@ static int RegisterDll(const char* strDll) return 0; } -static int UnregisterDll(char* strDll) +static int UnregisterDll(WCHAR *strDll) { HRESULT hr; DLLUNREGISTER pfUnregister; @@ -188,7 +183,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; @@ -217,15 +212,26 @@ 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 EmptyLine[1] = {0}; + WCHAR* command_line = NULL; + const WCHAR slashQW[] = {'/','?',0}; + const WCHAR hyphenQW[] = {'-','?',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); @@ -236,18 +242,25 @@ int main(int argc, char* argv[]) */ for(i = 1; i < argc; i++) { - if ((!strcasecmp(argv[i], "/u")) ||(!strcasecmp(argv[i], "-u"))) + if (!lstrcmpW(argv[i], slashQW) || !lstrcmpW(argv[i], hyphenQW)) + { + output_write(STRING_HEADER); + output_write(STRING_USAGE); + return 0; + } + else 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--; @@ -262,29 +275,13 @@ int main(int argc, char* argv[]) 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; - } } else - { - wsCommandLine = EmptyLine; - } + command_line[0] = '\0'; } - 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] == ':')) { @@ -294,7 +291,7 @@ int main(int argc, char* argv[]) } else { - char *DllName = argv[i]; + WCHAR *DllName = argv[i]; int res = 0; DllFound = TRUE; @@ -312,7 +309,7 @@ int main(int argc, char* argv[]) if (CallInstall) { - res = InstallDll(!Unregister, DllName, wsCommandLine); + res = InstallDll(!Unregister, DllName, command_line); } if (res) -- 1.8.3.2