2 * PURPOSE: Register an OLE component 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
25 * regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname
26 * [/u] unregister server
27 * [/s] silent (no message boxes)
28 * [/i] Call DllInstall passing it an optional [cmdline];
29 * when used with /u calls dll uninstall.
30 * [/n] Do not call DllRegisterServer; this option must be used with [/i]
34 * FIXME - currently receives command-line parameters in ASCII only and later
35 * converts to Unicode. Ideally the function should have wWinMain etry point
36 * and then work in Unicode only, but it seems Wine does not have necessary
41 #include "wine/port.h"
47 typedef HRESULT (*DLLREGISTER
) (void);
48 typedef HRESULT (*DLLUNREGISTER
) (void);
49 typedef HRESULT (*DLLINSTALL
) (BOOL
,LPCWSTR
);
55 printf("regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname\n");
56 printf("\t[/u] unregister server\n");
57 printf("\t[/s] silent (no message boxes)\n");
58 printf("\t[/i] Call DllInstall passing it an optional [cmdline];\n");
59 printf("\t when used with /u calls dll uninstall\n");
60 printf("\t[/n] Do not call DllRegisterServer; this option "
61 "must be used with [/i]\n");
69 * strDll - name of the dll.
70 * procName - name of the procedure to load from dll
71 * pDllHanlde - output variable receives handle of the loaded dll.
73 VOID
*LoadProc(char* strDll
, char* procName
, HMODULE
* DllHandle
)
77 *DllHandle
= LoadLibrary(strDll
);
81 printf("Dll %s not found\n", strDll
);
85 proc
= (VOID
*) GetProcAddress(*DllHandle
, procName
);
89 printf("%s not implemented in dll %s\n", procName
, strDll
);
90 FreeLibrary(*DllHandle
);
96 int RegisterDll(char* strDll
)
99 DLLREGISTER pfRegister
;
100 HMODULE DllHandle
= NULL
;
102 pfRegister
= LoadProc(strDll
, "DllRegisterServer", &DllHandle
);
108 printf("Failed to register dll %s\n", strDll
);
113 printf("Succesfully registered dll %s\n", strDll
);
116 FreeLibrary(DllHandle
);
120 int UnregisterDll(char* strDll
)
123 DLLUNREGISTER pfUnregister
;
124 HMODULE DllHandle
= NULL
;
126 pfUnregister
= LoadProc(strDll
, "DllUnregisterServer", &DllHandle
);
131 printf("Failed to unregister dll %s\n", strDll
);
136 printf("Succesfully unregistered dll %s\n", strDll
);
139 FreeLibrary(DllHandle
);
143 int InstallDll(BOOL install
, char *strDll
, WCHAR
*command_line
)
146 DLLINSTALL pfInstall
;
147 HMODULE DllHandle
= NULL
;
149 pfInstall
= LoadProc(strDll
, "DllInstall", &DllHandle
);
150 hr
= pfInstall(install
, command_line
);
154 printf("Failed to %s dll %s\n", install
? "install" : "uninstall",
159 printf("Succesfully %s dll %s\n", install
? "installed" : "uninstalled",
163 FreeLibrary(DllHandle
);
167 int main(int argc
, char* argv
[])
170 BOOL CallRegister
= TRUE
;
171 BOOL CallInstall
= FALSE
;
172 BOOL Unregister
= FALSE
;
173 BOOL DllFound
= FALSE
;
174 WCHAR
* wsCommandLine
= NULL
;
175 WCHAR EmptyLine
[1] = {0};
178 for(i
= 1; i
< argc
; i
++)
180 if (!strcasecmp(argv
[i
], "/u"))
182 else if (!strcasecmp(argv
[i
], "/s"))
184 else if (!strncasecmp(argv
[i
], "/i", strlen("/i")))
186 CHAR
* command_line
= argv
[i
] + strlen("/i");
189 if (command_line
[0] == ':' && command_line
[1])
191 int len
= strlen(command_line
);
195 /* remove double quotes */
196 if (command_line
[0] == '"')
203 command_line
[len
] = 0;
208 len
= MultiByteToWideChar(CP_ACP
, 0, command_line
, -1,
210 wsCommandLine
= HeapAlloc(GetProcessHeap(), 0,
211 len
* sizeof(WCHAR
));
213 MultiByteToWideChar(CP_ACP
, 0, command_line
, -1,
218 wsCommandLine
= EmptyLine
;
223 wsCommandLine
= EmptyLine
;
226 else if(!strcasecmp(argv
[i
], "/n"))
227 CallRegister
= FALSE
;
228 else if (argv
[i
][0] == '/' && (!argv
[i
][2] || argv
[i
][2] == ':'))
229 printf("Unrecognized switch %s\n", argv
[i
]);
232 char *DllName
= argv
[i
];
236 if (!CallInstall
|| (CallInstall
&& CallRegister
))
239 res
= UnregisterDll(DllName
);
241 res
= RegisterDll(DllName
);
249 res
= InstallDll(!Unregister
, DllName
, wsCommandLine
);