2002-04-29 23:47:39 +00:00
|
|
|
/*
|
2002-07-20 18:54:03 +00:00
|
|
|
* PURPOSE: Register OLE components in the registry
|
2002-04-29 23:47:39 +00:00
|
|
|
*
|
|
|
|
* Copyright 2001 ReactOS project
|
|
|
|
* Copyright 2001 Jurgen Van Gael [jurgen.vangael@student.kuleuven.ac.be]
|
|
|
|
* Copyright 2002 Andriy Palamarchuk
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-07-20 18:54:03 +00:00
|
|
|
*
|
2002-08-28 23:43:43 +00:00
|
|
|
* This version deliberately differs in error handling compared to the
|
2002-07-20 18:54:03 +00:00
|
|
|
* windows version.
|
2002-04-29 23:47:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
2002-07-20 18:54:03 +00:00
|
|
|
* regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname ...
|
2002-04-29 23:47:39 +00:00
|
|
|
* [/u] unregister server
|
|
|
|
* [/s] silent (no message boxes)
|
|
|
|
* [/i] Call DllInstall passing it an optional [cmdline];
|
|
|
|
* when used with /u calls dll uninstall.
|
|
|
|
* [/n] Do not call DllRegisterServer; this option must be used with [/i]
|
2006-04-17 09:14:54 +00:00
|
|
|
* [/c] Console output (seems to be deprecated and ignored)
|
2002-07-20 18:54:03 +00:00
|
|
|
*
|
|
|
|
* Note the complication that this version may be passed unix format file names
|
|
|
|
* which might be mistaken for flags. Conveniently the Windows version
|
2002-08-28 23:43:43 +00:00
|
|
|
* requires each flag to be separate (e.g. no /su ) and so we will simply
|
2002-07-20 18:54:03 +00:00
|
|
|
* assume that anything longer than /. is a filename.
|
2002-04-29 23:47:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FIXME - currently receives command-line parameters in ASCII only and later
|
2002-07-20 18:54:03 +00:00
|
|
|
* converts to Unicode. Ideally the function should have wWinMain entry point
|
2002-04-29 23:47:39 +00:00
|
|
|
* and then work in Unicode only, but it seems Wine does not have necessary
|
|
|
|
* support.
|
|
|
|
*/
|
|
|
|
|
2006-01-18 13:23:11 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
2002-06-13 19:11:53 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2002-04-29 23:47:39 +00:00
|
|
|
#include <windows.h>
|
2006-02-09 16:48:12 +00:00
|
|
|
#include <ole2.h>
|
2014-03-19 00:54:57 +00:00
|
|
|
#include "regsvr32.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(regsvr32);
|
2002-04-29 23:47:39 +00:00
|
|
|
|
|
|
|
typedef HRESULT (*DLLREGISTER) (void);
|
|
|
|
typedef HRESULT (*DLLUNREGISTER) (void);
|
|
|
|
typedef HRESULT (*DLLINSTALL) (BOOL,LPCWSTR);
|
|
|
|
|
2013-11-05 00:06:04 +00:00
|
|
|
static BOOL Silent = FALSE;
|
2002-04-29 23:47:39 +00:00
|
|
|
|
2014-03-19 00:54:57 +00:00
|
|
|
static void __cdecl output_write(UINT id, ...)
|
2002-04-29 23:47:39 +00:00
|
|
|
{
|
2014-03-19 00:54:57 +00:00
|
|
|
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);
|
2002-04-29 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads procedure.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* strDll - name of the dll.
|
|
|
|
* procName - name of the procedure to load from dll
|
|
|
|
* pDllHanlde - output variable receives handle of the loaded dll.
|
|
|
|
*/
|
2005-06-04 10:01:25 +00:00
|
|
|
static VOID *LoadProc(const char* strDll, const char* procName, HMODULE* DllHandle)
|
2002-04-29 23:47:39 +00:00
|
|
|
{
|
|
|
|
VOID* (*proc)(void);
|
|
|
|
|
2008-09-03 09:30:44 +00:00
|
|
|
*DllHandle = LoadLibraryExA(strDll, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
|
2002-04-29 23:47:39 +00:00
|
|
|
if(!*DllHandle)
|
|
|
|
{
|
|
|
|
if(!Silent)
|
2014-03-19 00:54:57 +00:00
|
|
|
output_write(STRING_DLL_LOAD_FAILED, strDll);
|
2002-04-29 23:47:39 +00:00
|
|
|
|
2006-01-18 13:23:11 +00:00
|
|
|
ExitProcess(1);
|
2002-04-29 23:47:39 +00:00
|
|
|
}
|
|
|
|
proc = (VOID *) GetProcAddress(*DllHandle, procName);
|
|
|
|
if(!proc)
|
|
|
|
{
|
|
|
|
if(!Silent)
|
2014-03-19 00:54:57 +00:00
|
|
|
output_write(STRING_PROC_NOT_IMPLEMENTED, procName, strDll);
|
2002-04-29 23:47:39 +00:00
|
|
|
FreeLibrary(*DllHandle);
|
2010-05-02 06:24:40 +00:00
|
|
|
return NULL;
|
2002-04-29 23:47:39 +00:00
|
|
|
}
|
|
|
|
return proc;
|
|
|
|
}
|
|
|
|
|
2005-06-04 10:01:25 +00:00
|
|
|
static int RegisterDll(const char* strDll)
|
2002-04-29 23:47:39 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DLLREGISTER pfRegister;
|
|
|
|
HMODULE DllHandle = NULL;
|
|
|
|
|
|
|
|
pfRegister = LoadProc(strDll, "DllRegisterServer", &DllHandle);
|
2010-05-02 06:24:40 +00:00
|
|
|
if (!pfRegister)
|
|
|
|
return 0;
|
2002-04-29 23:47:39 +00:00
|
|
|
|
|
|
|
hr = pfRegister();
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
if(!Silent)
|
2014-03-19 00:54:57 +00:00
|
|
|
output_write(STRING_REGISTER_FAILED, strDll);
|
2002-04-29 23:47:39 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(!Silent)
|
2014-03-19 00:54:57 +00:00
|
|
|
output_write(STRING_REGISTER_SUCCESSFUL, strDll);
|
2002-04-29 23:47:39 +00:00
|
|
|
|
|
|
|
if(DllHandle)
|
|
|
|
FreeLibrary(DllHandle);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-04 10:01:25 +00:00
|
|
|
static int UnregisterDll(char* strDll)
|
2002-04-29 23:47:39 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DLLUNREGISTER pfUnregister;
|
|
|
|
HMODULE DllHandle = NULL;
|
|
|
|
|
|
|
|
pfUnregister = LoadProc(strDll, "DllUnregisterServer", &DllHandle);
|
2010-05-02 06:24:40 +00:00
|
|
|
if (!pfUnregister)
|
|
|
|
return 0;
|
|
|
|
|
2002-04-29 23:47:39 +00:00
|
|
|
hr = pfUnregister();
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
if(!Silent)
|
2014-03-19 00:54:57 +00:00
|
|
|
output_write(STRING_UNREGISTER_FAILED, strDll);
|
2002-04-29 23:47:39 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(!Silent)
|
2014-03-19 00:54:57 +00:00
|
|
|
output_write(STRING_UNREGISTER_SUCCESSFUL, strDll);
|
2002-04-29 23:47:39 +00:00
|
|
|
|
|
|
|
if(DllHandle)
|
|
|
|
FreeLibrary(DllHandle);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-04 10:01:25 +00:00
|
|
|
static int InstallDll(BOOL install, char *strDll, WCHAR *command_line)
|
2002-04-29 23:47:39 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DLLINSTALL pfInstall;
|
|
|
|
HMODULE DllHandle = NULL;
|
|
|
|
|
|
|
|
pfInstall = LoadProc(strDll, "DllInstall", &DllHandle);
|
2010-05-02 06:24:40 +00:00
|
|
|
if (!pfInstall)
|
|
|
|
return 0;
|
|
|
|
|
2002-04-29 23:47:39 +00:00
|
|
|
hr = pfInstall(install, command_line);
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
if(!Silent)
|
2014-03-19 00:54:57 +00:00
|
|
|
{
|
|
|
|
if (install)
|
|
|
|
output_write(STRING_INSTALL_FAILED, strDll);
|
|
|
|
else
|
|
|
|
output_write(STRING_UNINSTALL_FAILED, strDll);
|
|
|
|
}
|
2002-04-29 23:47:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(!Silent)
|
2014-03-19 00:54:57 +00:00
|
|
|
{
|
|
|
|
if (install)
|
|
|
|
output_write(STRING_INSTALL_SUCCESSFUL, strDll);
|
|
|
|
else
|
|
|
|
output_write(STRING_UNINSTALL_SUCCESSFUL, strDll);
|
|
|
|
}
|
2002-04-29 23:47:39 +00:00
|
|
|
|
|
|
|
if(DllHandle)
|
|
|
|
FreeLibrary(DllHandle);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BOOL CallRegister = TRUE;
|
|
|
|
BOOL CallInstall = FALSE;
|
|
|
|
BOOL Unregister = FALSE;
|
|
|
|
BOOL DllFound = FALSE;
|
|
|
|
WCHAR* wsCommandLine = NULL;
|
|
|
|
WCHAR EmptyLine[1] = {0};
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2006-02-09 16:48:12 +00:00
|
|
|
OleInitialize(NULL);
|
2002-04-29 23:47:39 +00:00
|
|
|
|
2002-07-20 18:54:03 +00:00
|
|
|
/* Strictly, the Microsoft version processes all the flags before
|
2014-03-19 00:54:57 +00:00
|
|
|
* the files (e.g. regsvr32 file1 /s file2 is silent even for file1).
|
2002-07-20 18:54:03 +00:00
|
|
|
* For ease, we will not replicate that and will process the arguments
|
|
|
|
* in order.
|
|
|
|
*/
|
2002-04-29 23:47:39 +00:00
|
|
|
for(i = 1; i < argc; i++)
|
|
|
|
{
|
2006-01-16 20:30:38 +00:00
|
|
|
if ((!strcasecmp(argv[i], "/u")) ||(!strcasecmp(argv[i], "-u")))
|
2002-04-29 23:47:39 +00:00
|
|
|
Unregister = TRUE;
|
2006-01-16 20:30:38 +00:00
|
|
|
else if ((!strcasecmp(argv[i], "/s"))||(!strcasecmp(argv[i], "-s")))
|
2013-11-05 00:06:04 +00:00
|
|
|
Silent = TRUE;
|
2006-01-16 20:30:38 +00:00
|
|
|
else if ((!strncasecmp(argv[i], "/i", strlen("/i")))||(!strncasecmp(argv[i], "-i", strlen("-i"))))
|
2002-04-29 23:47:39 +00:00
|
|
|
{
|
|
|
|
CHAR* command_line = argv[i] + strlen("/i");
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-04-29 23:47:39 +00:00
|
|
|
CallInstall = TRUE;
|
2002-05-31 23:06:46 +00:00
|
|
|
if (command_line[0] == ':' && command_line[1])
|
2002-04-29 23:47:39 +00:00
|
|
|
{
|
|
|
|
int len = strlen(command_line);
|
|
|
|
|
|
|
|
command_line++;
|
|
|
|
len--;
|
|
|
|
/* remove double quotes */
|
|
|
|
if (command_line[0] == '"')
|
|
|
|
{
|
|
|
|
command_line++;
|
|
|
|
len--;
|
|
|
|
if (command_line[0])
|
|
|
|
{
|
|
|
|
len--;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
else
|
2002-04-29 23:47:39 +00:00
|
|
|
{
|
|
|
|
wsCommandLine = EmptyLine;
|
|
|
|
}
|
|
|
|
}
|
2006-01-16 20:30:38 +00:00
|
|
|
else if((!strcasecmp(argv[i], "/n"))||(!strcasecmp(argv[i], "-n")))
|
2002-04-29 23:47:39 +00:00
|
|
|
CallRegister = FALSE;
|
2006-04-17 09:14:54 +00:00
|
|
|
else if((!strcasecmp(argv[i], "/c"))||(!strcasecmp(argv[i], "-c")))
|
|
|
|
/* console output */;
|
2002-04-29 23:47:39 +00:00
|
|
|
else if (argv[i][0] == '/' && (!argv[i][2] || argv[i][2] == ':'))
|
2014-03-19 00:54:57 +00:00
|
|
|
{
|
|
|
|
output_write(STRING_UNRECOGNIZED_SWITCH, argv[i]);
|
|
|
|
output_write(STRING_USAGE);
|
|
|
|
return 1;
|
|
|
|
}
|
2002-04-29 23:47:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char *DllName = argv[i];
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
DllFound = TRUE;
|
|
|
|
if (!CallInstall || (CallInstall && CallRegister))
|
|
|
|
{
|
|
|
|
if(Unregister)
|
|
|
|
res = UnregisterDll(DllName);
|
|
|
|
else
|
|
|
|
res = RegisterDll(DllName);
|
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-04-29 23:47:39 +00:00
|
|
|
if (res)
|
|
|
|
return res;
|
2002-07-20 18:54:03 +00:00
|
|
|
/* Confirmed. The windows version does stop on the first error.*/
|
2002-04-29 23:47:39 +00:00
|
|
|
|
|
|
|
if (CallInstall)
|
|
|
|
{
|
|
|
|
res = InstallDll(!Unregister, DllName, wsCommandLine);
|
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-07-20 18:54:03 +00:00
|
|
|
if (res)
|
|
|
|
return res;
|
2002-04-29 23:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!DllFound)
|
|
|
|
{
|
|
|
|
if(!Silent)
|
2014-03-19 00:54:57 +00:00
|
|
|
{
|
|
|
|
output_write(STRING_HEADER);
|
|
|
|
output_write(STRING_USAGE);
|
|
|
|
}
|
|
|
|
return 1;
|
2002-04-29 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
2006-02-09 16:48:12 +00:00
|
|
|
OleUninitialize();
|
|
|
|
|
2002-04-29 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|