2 * PURPOSE: Register OLE components in the registry
4 * Copyright 2001 ReactOS project
5 * Copyright 2001 Jurgen Van Gael [jurgen.vangael@student.kuleuven.ac.be]
6 * Copyright 2002 Andriy Palamarchuk
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * This version deliberately differs in error handling compared to the
28 * regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname ...
29 * [/u] unregister server
30 * [/s] silent (no message boxes)
31 * [/i] Call DllInstall passing it an optional [cmdline];
32 * when used with /u calls dll uninstall.
33 * [/n] Do not call DllRegisterServer; this option must be used with [/i]
35 * Note the complication that this version may be passed unix format file names
36 * which might be mistaken for flags. Conveniently the Windows version
37 * requires each flag to be separate (e.g. no /su ) and so we will simply
38 * assume that anything longer than /. is a filename.
42 * FIXME - currently receives command-line parameters in ASCII only and later
43 * converts to Unicode. Ideally the function should have wWinMain entry point
44 * and then work in Unicode only, but it seems Wine does not have necessary
49 #include "wine/port.h"
55 typedef HRESULT (*DLLREGISTER) (void);
56 typedef HRESULT (*DLLUNREGISTER) (void);
57 typedef HRESULT (*DLLINSTALL) (BOOL,LPCWSTR);
63 printf("regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname ...\n");
64 printf("\t[/u] unregister server\n");
65 printf("\t[/s] silent (no message boxes)\n");
66 printf("\t[/i] Call DllInstall passing it an optional [cmdline];\n");
67 printf("\t when used with /u calls dll uninstall\n");
68 printf("\t[/n] Do not call DllRegisterServer; this option "
69 "must be used with [/i]\n");
77 * strDll - name of the dll.
78 * procName - name of the procedure to load from dll
79 * pDllHanlde - output variable receives handle of the loaded dll.
81 VOID *LoadProc(char* strDll, char* procName, HMODULE* DllHandle)
85 *DllHandle = LoadLibrary(strDll);
89 printf("Dll %s not found\n", strDll);
93 proc = (VOID *) GetProcAddress(*DllHandle, procName);
97 printf("%s not implemented in dll %s\n", procName, strDll);
98 FreeLibrary(*DllHandle);
104 int RegisterDll(char* strDll)
107 DLLREGISTER pfRegister;
108 HMODULE DllHandle = NULL;
110 pfRegister = LoadProc(strDll, "DllRegisterServer", &DllHandle);
116 printf("Failed to register dll %s\n", strDll);
121 printf("Succesfully registered dll %s\n", strDll);
124 FreeLibrary(DllHandle);
128 int UnregisterDll(char* strDll)
131 DLLUNREGISTER pfUnregister;
132 HMODULE DllHandle = NULL;
134 pfUnregister = LoadProc(strDll, "DllUnregisterServer", &DllHandle);
139 printf("Failed to unregister dll %s\n", strDll);
144 printf("Succesfully unregistered dll %s\n", strDll);
147 FreeLibrary(DllHandle);
151 int InstallDll(BOOL install, char *strDll, WCHAR *command_line)
154 DLLINSTALL pfInstall;
155 HMODULE DllHandle = NULL;
157 pfInstall = LoadProc(strDll, "DllInstall", &DllHandle);
158 hr = pfInstall(install, command_line);
162 printf("Failed to %s dll %s\n", install ? "install" : "uninstall",
167 printf("Succesfully %s dll %s\n", install ? "installed" : "uninstalled",
171 FreeLibrary(DllHandle);
175 int main(int argc, char* argv[])
178 BOOL CallRegister = TRUE;
179 BOOL CallInstall = FALSE;
180 BOOL Unregister = FALSE;
181 BOOL DllFound = FALSE;
182 WCHAR* wsCommandLine = NULL;
183 WCHAR EmptyLine[1] = {0};
186 /* Strictly, the Microsoft version processes all the flags before
187 * the files (e.g. regsvr32 file1 /s file2 is silent even for file1.
188 * For ease, we will not replicate that and will process the arguments
191 for(i = 1; i < argc; i++)
193 if (!strcasecmp(argv[i], "/u"))
195 else if (!strcasecmp(argv[i], "/s"))
197 else if (!strncasecmp(argv[i], "/i", strlen("/i")))
199 CHAR* command_line = argv[i] + strlen("/i");
202 if (command_line[0] == ':' && command_line[1])
204 int len = strlen(command_line);
208 /* remove double quotes */
209 if (command_line[0] == '"')
216 command_line[len] = 0;
221 len = MultiByteToWideChar(CP_ACP, 0, command_line, -1,
223 wsCommandLine = HeapAlloc(GetProcessHeap(), 0,
224 len * sizeof(WCHAR));
226 MultiByteToWideChar(CP_ACP, 0, command_line, -1,
231 wsCommandLine = EmptyLine;
236 wsCommandLine = EmptyLine;
239 else if(!strcasecmp(argv[i], "/n"))
240 CallRegister = FALSE;
241 else if (argv[i][0] == '/' && (!argv[i][2] || argv[i][2] == ':'))
242 printf("Unrecognized switch %s\n", argv[i]);
245 char *DllName = argv[i];
249 if (!CallInstall || (CallInstall && CallRegister))
252 res = UnregisterDll(DllName);
254 res = RegisterDll(DllName);
259 /* Confirmed. The windows version does stop on the first error.*/
263 res = InstallDll(!Unregister, DllName, wsCommandLine);