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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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]
34 * [/c] Console output (seems to be deprecated and ignored)
36 * Note the complication that this version may be passed unix format file names
37 * which might be mistaken for flags. Conveniently the Windows version
38 * requires each flag to be separate (e.g. no /su ) and so we will simply
39 * assume that anything longer than /. is a filename.
43 * FIXME - currently receives command-line parameters in ASCII only and later
44 * converts to Unicode. Ideally the function should have wWinMain entry point
45 * and then work in Unicode only, but it seems Wine does not have necessary
49 #define WIN32_LEAN_AND_MEAN
52 #include "wine/port.h"
58 #include "wine/debug.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(regsvr32
);
62 typedef HRESULT (*DLLREGISTER
) (void);
63 typedef HRESULT (*DLLUNREGISTER
) (void);
64 typedef HRESULT (*DLLINSTALL
) (BOOL
,LPCWSTR
);
66 static BOOL Silent
= FALSE
;
68 static void __cdecl
output_write(UINT id
, ...)
77 if (!LoadStringA(GetModuleHandleA(NULL
), id
, fmt
, sizeof(fmt
)/sizeof(fmt
[0])))
79 WINE_FIXME("LoadString failed with %d\n", GetLastError());
83 __ms_va_start(va_args
, id
);
84 SetLastError(NO_ERROR
);
85 len
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ALLOCATE_BUFFER
,
86 fmt
, 0, 0, (LPSTR
)&str
, 0, &va_args
);
88 if (len
== 0 && GetLastError() != NO_ERROR
)
90 WINE_FIXME("Could not format string: le=%u, fmt=%s\n", GetLastError(), wine_dbgstr_a(fmt
));
94 ret
= WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE
), str
, len
, &nOut
, NULL
);
97 WINE_WARN("regsvr32: WriteConsoleA() failed.\n");
106 * strDll - name of the dll.
107 * procName - name of the procedure to load from dll
108 * pDllHanlde - output variable receives handle of the loaded dll.
110 static VOID
*LoadProc(const char* strDll
, const char* procName
, HMODULE
* DllHandle
)
114 *DllHandle
= LoadLibraryExA(strDll
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
117 output_write(STRING_DLL_LOAD_FAILED
, strDll
);
120 proc
= (VOID
*) GetProcAddress(*DllHandle
, procName
);
123 output_write(STRING_PROC_NOT_IMPLEMENTED
, procName
, strDll
);
124 FreeLibrary(*DllHandle
);
130 static int RegisterDll(const char* strDll
)
133 DLLREGISTER pfRegister
;
134 HMODULE DllHandle
= NULL
;
136 pfRegister
= LoadProc(strDll
, "DllRegisterServer", &DllHandle
);
143 output_write(STRING_REGISTER_FAILED
, strDll
);
146 output_write(STRING_REGISTER_SUCCESSFUL
, strDll
);
149 FreeLibrary(DllHandle
);
153 static int UnregisterDll(char* strDll
)
156 DLLUNREGISTER pfUnregister
;
157 HMODULE DllHandle
= NULL
;
159 pfUnregister
= LoadProc(strDll
, "DllUnregisterServer", &DllHandle
);
166 output_write(STRING_UNREGISTER_FAILED
, strDll
);
169 output_write(STRING_UNREGISTER_SUCCESSFUL
, strDll
);
172 FreeLibrary(DllHandle
);
176 static int InstallDll(BOOL install
, char *strDll
, WCHAR
*command_line
)
179 DLLINSTALL pfInstall
;
180 HMODULE DllHandle
= NULL
;
182 pfInstall
= LoadProc(strDll
, "DllInstall", &DllHandle
);
186 hr
= pfInstall(install
, command_line
);
190 output_write(STRING_INSTALL_FAILED
, strDll
);
192 output_write(STRING_UNINSTALL_FAILED
, strDll
);
196 output_write(STRING_INSTALL_SUCCESSFUL
, strDll
);
198 output_write(STRING_UNINSTALL_SUCCESSFUL
, strDll
);
201 FreeLibrary(DllHandle
);
205 int main(int argc
, char* argv
[])
208 BOOL CallRegister
= TRUE
;
209 BOOL CallInstall
= FALSE
;
210 BOOL Unregister
= FALSE
;
211 BOOL DllFound
= FALSE
;
212 WCHAR
* wsCommandLine
= NULL
;
213 WCHAR EmptyLine
[1] = {0};
217 /* Strictly, the Microsoft version processes all the flags before
218 * the files (e.g. regsvr32 file1 /s file2 is silent even for file1).
219 * For ease, we will not replicate that and will process the arguments
222 for(i
= 1; i
< argc
; i
++)
224 if ((!strcasecmp(argv
[i
], "/u")) ||(!strcasecmp(argv
[i
], "-u")))
226 else if ((!strcasecmp(argv
[i
], "/s"))||(!strcasecmp(argv
[i
], "-s")))
228 else if ((!strncasecmp(argv
[i
], "/i", strlen("/i")))||(!strncasecmp(argv
[i
], "-i", strlen("-i"))))
230 CHAR
* command_line
= argv
[i
] + strlen("/i");
233 if (command_line
[0] == ':' && command_line
[1])
235 int len
= strlen(command_line
);
239 /* remove double quotes */
240 if (command_line
[0] == '"')
247 command_line
[len
] = 0;
252 len
= MultiByteToWideChar(CP_ACP
, 0, command_line
, -1,
254 wsCommandLine
= HeapAlloc(GetProcessHeap(), 0,
255 len
* sizeof(WCHAR
));
257 MultiByteToWideChar(CP_ACP
, 0, command_line
, -1,
262 wsCommandLine
= EmptyLine
;
267 wsCommandLine
= EmptyLine
;
270 else if((!strcasecmp(argv
[i
], "/n"))||(!strcasecmp(argv
[i
], "-n")))
271 CallRegister
= FALSE
;
272 else if((!strcasecmp(argv
[i
], "/c"))||(!strcasecmp(argv
[i
], "-c")))
273 /* console output */;
274 else if (argv
[i
][0] == '/' && (!argv
[i
][2] || argv
[i
][2] == ':'))
276 output_write(STRING_UNRECOGNIZED_SWITCH
, argv
[i
]);
277 output_write(STRING_USAGE
);
282 char *DllName
= argv
[i
];
286 if (!CallInstall
|| (CallInstall
&& CallRegister
))
289 res
= UnregisterDll(DllName
);
291 res
= RegisterDll(DllName
);
296 /* Confirmed. The windows version does stop on the first error.*/
300 res
= InstallDll(!Unregister
, DllName
, wsCommandLine
);
310 output_write(STRING_HEADER
);
311 output_write(STRING_USAGE
);