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
, ...)
75 if (!LoadStringA(GetModuleHandleA(NULL
), id
, fmt
, sizeof(fmt
)/sizeof(fmt
[0])))
77 WINE_FIXME("LoadString failed with %d\n", GetLastError());
81 __ms_va_start(va_args
, id
);
82 SetLastError(NO_ERROR
);
83 len
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ALLOCATE_BUFFER
,
84 fmt
, 0, 0, (LPSTR
)&str
, 0, &va_args
);
86 if (len
== 0 && GetLastError() != NO_ERROR
)
88 WINE_FIXME("Could not format string: le=%u, fmt=%s\n", GetLastError(), wine_dbgstr_a(fmt
));
92 ret
= WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE
), str
, len
, &nOut
, NULL
);
95 WINE_WARN("regsvr32: WriteConsoleA() failed.\n");
104 * strDll - name of the dll.
105 * procName - name of the procedure to load from dll
106 * pDllHanlde - output variable receives handle of the loaded dll.
108 static VOID
*LoadProc(const char* strDll
, const char* procName
, HMODULE
* DllHandle
)
112 *DllHandle
= LoadLibraryExA(strDll
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
116 output_write(STRING_DLL_LOAD_FAILED
, strDll
);
120 proc
= (VOID
*) GetProcAddress(*DllHandle
, procName
);
124 output_write(STRING_PROC_NOT_IMPLEMENTED
, procName
, strDll
);
125 FreeLibrary(*DllHandle
);
131 static int RegisterDll(const char* strDll
)
134 DLLREGISTER pfRegister
;
135 HMODULE DllHandle
= NULL
;
137 pfRegister
= LoadProc(strDll
, "DllRegisterServer", &DllHandle
);
145 output_write(STRING_REGISTER_FAILED
, strDll
);
150 output_write(STRING_REGISTER_SUCCESSFUL
, strDll
);
153 FreeLibrary(DllHandle
);
157 static int UnregisterDll(char* strDll
)
160 DLLUNREGISTER pfUnregister
;
161 HMODULE DllHandle
= NULL
;
163 pfUnregister
= LoadProc(strDll
, "DllUnregisterServer", &DllHandle
);
171 output_write(STRING_UNREGISTER_FAILED
, strDll
);
176 output_write(STRING_UNREGISTER_SUCCESSFUL
, strDll
);
179 FreeLibrary(DllHandle
);
183 static int InstallDll(BOOL install
, char *strDll
, WCHAR
*command_line
)
186 DLLINSTALL pfInstall
;
187 HMODULE DllHandle
= NULL
;
189 pfInstall
= LoadProc(strDll
, "DllInstall", &DllHandle
);
193 hr
= pfInstall(install
, command_line
);
199 output_write(STRING_INSTALL_FAILED
, strDll
);
201 output_write(STRING_UNINSTALL_FAILED
, strDll
);
208 output_write(STRING_INSTALL_SUCCESSFUL
, strDll
);
210 output_write(STRING_UNINSTALL_SUCCESSFUL
, strDll
);
214 FreeLibrary(DllHandle
);
218 int main(int argc
, char* argv
[])
221 BOOL CallRegister
= TRUE
;
222 BOOL CallInstall
= FALSE
;
223 BOOL Unregister
= FALSE
;
224 BOOL DllFound
= FALSE
;
225 WCHAR
* wsCommandLine
= NULL
;
226 WCHAR EmptyLine
[1] = {0};
230 /* Strictly, the Microsoft version processes all the flags before
231 * the files (e.g. regsvr32 file1 /s file2 is silent even for file1).
232 * For ease, we will not replicate that and will process the arguments
235 for(i
= 1; i
< argc
; i
++)
237 if ((!strcasecmp(argv
[i
], "/u")) ||(!strcasecmp(argv
[i
], "-u")))
239 else if ((!strcasecmp(argv
[i
], "/s"))||(!strcasecmp(argv
[i
], "-s")))
241 else if ((!strncasecmp(argv
[i
], "/i", strlen("/i")))||(!strncasecmp(argv
[i
], "-i", strlen("-i"))))
243 CHAR
* command_line
= argv
[i
] + strlen("/i");
246 if (command_line
[0] == ':' && command_line
[1])
248 int len
= strlen(command_line
);
252 /* remove double quotes */
253 if (command_line
[0] == '"')
260 command_line
[len
] = 0;
265 len
= MultiByteToWideChar(CP_ACP
, 0, command_line
, -1,
267 wsCommandLine
= HeapAlloc(GetProcessHeap(), 0,
268 len
* sizeof(WCHAR
));
270 MultiByteToWideChar(CP_ACP
, 0, command_line
, -1,
275 wsCommandLine
= EmptyLine
;
280 wsCommandLine
= EmptyLine
;
283 else if((!strcasecmp(argv
[i
], "/n"))||(!strcasecmp(argv
[i
], "-n")))
284 CallRegister
= FALSE
;
285 else if((!strcasecmp(argv
[i
], "/c"))||(!strcasecmp(argv
[i
], "-c")))
286 /* console output */;
287 else if (argv
[i
][0] == '/' && (!argv
[i
][2] || argv
[i
][2] == ':'))
289 output_write(STRING_UNRECOGNIZED_SWITCH
, argv
[i
]);
290 output_write(STRING_USAGE
);
295 char *DllName
= argv
[i
];
299 if (!CallInstall
|| (CallInstall
&& CallRegister
))
302 res
= UnregisterDll(DllName
);
304 res
= RegisterDll(DllName
);
309 /* Confirmed. The windows version does stop on the first error.*/
313 res
= InstallDll(!Unregister
, DllName
, wsCommandLine
);
325 output_write(STRING_HEADER
);
326 output_write(STRING_USAGE
);