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
43 typedef HRESULT (*DLLREGISTER
) (void);
44 typedef HRESULT (*DLLUNREGISTER
) (void);
45 typedef HRESULT (*DLLINSTALL
) (BOOL
,LPCWSTR
);
51 printf("regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname\n");
52 printf("\t[/u] unregister server\n");
53 printf("\t[/s] silent (no message boxes)\n");
54 printf("\t[/i] Call DllInstall passing it an optional [cmdline];\n");
55 printf("\t when used with /u calls dll uninstall\n");
56 printf("\t[/n] Do not call DllRegisterServer; this option "
57 "must be used with [/i]\n");
65 * strDll - name of the dll.
66 * procName - name of the procedure to load from dll
67 * pDllHanlde - output variable receives handle of the loaded dll.
69 VOID
*LoadProc(char* strDll
, char* procName
, HMODULE
* DllHandle
)
73 *DllHandle
= LoadLibrary(strDll
);
77 printf("Dll %s not found\n", strDll
);
81 proc
= (VOID
*) GetProcAddress(*DllHandle
, procName
);
85 printf("%s not implemented in dll %s\n", procName
, strDll
);
86 FreeLibrary(*DllHandle
);
92 int RegisterDll(char* strDll
)
95 DLLREGISTER pfRegister
;
96 HMODULE DllHandle
= NULL
;
98 pfRegister
= LoadProc(strDll
, "DllRegisterServer", &DllHandle
);
104 printf("Failed to register dll %s\n", strDll
);
109 printf("Succesfully registered dll %s\n", strDll
);
112 FreeLibrary(DllHandle
);
116 int UnregisterDll(char* strDll
)
119 DLLUNREGISTER pfUnregister
;
120 HMODULE DllHandle
= NULL
;
122 pfUnregister
= LoadProc(strDll
, "DllUnregisterServer", &DllHandle
);
127 printf("Failed to unregister dll %s\n", strDll
);
132 printf("Succesfully unregistered dll %s\n", strDll
);
135 FreeLibrary(DllHandle
);
139 int InstallDll(BOOL install
, char *strDll
, WCHAR
*command_line
)
142 DLLINSTALL pfInstall
;
143 HMODULE DllHandle
= NULL
;
145 pfInstall
= LoadProc(strDll
, "DllInstall", &DllHandle
);
146 hr
= pfInstall(install
, command_line
);
150 printf("Failed to %s dll %s\n", install
? "install" : "uninstall",
155 printf("Succesfully %s dll %s\n", install
? "installed" : "uninstalled",
159 FreeLibrary(DllHandle
);
163 int main(int argc
, char* argv
[])
166 BOOL CallRegister
= TRUE
;
167 BOOL CallInstall
= FALSE
;
168 BOOL Unregister
= FALSE
;
169 BOOL DllFound
= FALSE
;
170 WCHAR
* wsCommandLine
= NULL
;
171 WCHAR EmptyLine
[1] = {0};
174 for(i
= 1; i
< argc
; i
++)
176 if (!stricmp(argv
[i
], "/u"))
178 else if (!stricmp(argv
[i
], "/s"))
180 else if (!strnicmp(argv
[i
], "/i", strlen("/i")))
182 CHAR
* command_line
= argv
[i
] + strlen("/i");
185 if (command_line
[0] == ':' && command_line
[1])
187 int len
= strlen(command_line
);
191 /* remove double quotes */
192 if (command_line
[0] == '"')
199 command_line
[len
] = 0;
204 len
= MultiByteToWideChar(CP_ACP
, 0, command_line
, -1,
206 wsCommandLine
= HeapAlloc(GetProcessHeap(), 0,
207 len
* sizeof(WCHAR
));
209 MultiByteToWideChar(CP_ACP
, 0, command_line
, -1,
214 wsCommandLine
= EmptyLine
;
219 wsCommandLine
= EmptyLine
;
222 else if(!stricmp(argv
[i
], "/n"))
223 CallRegister
= FALSE
;
224 else if (argv
[i
][0] == '/' && (!argv
[i
][2] || argv
[i
][2] == ':'))
225 printf("Unrecognized switch %s\n", argv
[i
]);
228 char *DllName
= argv
[i
];
232 if (!CallInstall
|| (CallInstall
&& CallRegister
))
235 res
= UnregisterDll(DllName
);
237 res
= RegisterDll(DllName
);
245 res
= InstallDll(!Unregister
, DllName
, wsCommandLine
);