X11DRV_GetDIBits: Don't clear the biCompression==BI_BITFIELDS flag
[wine/testsucceed.git] / programs / regsvr32 / regsvr32.c
blobfb248a41919f91dd487b88f527e3168d7c1efa1e
1 /*
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]
33 /**
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
37 * support.
40 #include "config.h"
41 #include "wine/port.h"
43 #include <stdio.h>
44 #include <string.h>
45 #include <windows.h>
47 typedef HRESULT (*DLLREGISTER) (void);
48 typedef HRESULT (*DLLUNREGISTER) (void);
49 typedef HRESULT (*DLLINSTALL) (BOOL,LPCWSTR);
51 int Silent = 0;
53 int Usage()
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");
62 return 0;
65 /**
66 * Loads procedure.
68 * Parameters:
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)
75 VOID* (*proc)(void);
77 *DllHandle = LoadLibrary(strDll);
78 if(!*DllHandle)
80 if(!Silent)
81 printf("Dll %s not found\n", strDll);
83 exit(-1);
85 proc = (VOID *) GetProcAddress(*DllHandle, procName);
86 if(!proc)
88 if(!Silent)
89 printf("%s not implemented in dll %s\n", procName, strDll);
90 FreeLibrary(*DllHandle);
91 exit(-1);
93 return proc;
96 int RegisterDll(char* strDll)
98 HRESULT hr;
99 DLLREGISTER pfRegister;
100 HMODULE DllHandle = NULL;
102 pfRegister = LoadProc(strDll, "DllRegisterServer", &DllHandle);
104 hr = pfRegister();
105 if(FAILED(hr))
107 if(!Silent)
108 printf("Failed to register dll %s\n", strDll);
110 return -1;
112 if(!Silent)
113 printf("Succesfully registered dll %s\n", strDll);
115 if(DllHandle)
116 FreeLibrary(DllHandle);
117 return 0;
120 int UnregisterDll(char* strDll)
122 HRESULT hr;
123 DLLUNREGISTER pfUnregister;
124 HMODULE DllHandle = NULL;
126 pfUnregister = LoadProc(strDll, "DllUnregisterServer", &DllHandle);
127 hr = pfUnregister();
128 if(FAILED(hr))
130 if(!Silent)
131 printf("Failed to unregister dll %s\n", strDll);
133 return -1;
135 if(!Silent)
136 printf("Succesfully unregistered dll %s\n", strDll);
138 if(DllHandle)
139 FreeLibrary(DllHandle);
140 return 0;
143 int InstallDll(BOOL install, char *strDll, WCHAR *command_line)
145 HRESULT hr;
146 DLLINSTALL pfInstall;
147 HMODULE DllHandle = NULL;
149 pfInstall = LoadProc(strDll, "DllInstall", &DllHandle);
150 hr = pfInstall(install, command_line);
151 if(FAILED(hr))
153 if(!Silent)
154 printf("Failed to %s dll %s\n", install ? "install" : "uninstall",
155 strDll);
156 return -1;
158 if(!Silent)
159 printf("Succesfully %s dll %s\n", install ? "installed" : "uninstalled",
160 strDll);
162 if(DllHandle)
163 FreeLibrary(DllHandle);
164 return 0;
167 int main(int argc, char* argv[])
169 int i;
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"))
181 Unregister = TRUE;
182 else if (!strcasecmp(argv[i], "/s"))
183 Silent = 1;
184 else if (!strncasecmp(argv[i], "/i", strlen("/i")))
186 CHAR* command_line = argv[i] + strlen("/i");
188 CallInstall = TRUE;
189 if (command_line[0] == ':' && command_line[1])
191 int len = strlen(command_line);
193 command_line++;
194 len--;
195 /* remove double quotes */
196 if (command_line[0] == '"')
198 command_line++;
199 len--;
200 if (command_line[0])
202 len--;
203 command_line[len] = 0;
206 if (command_line[0])
208 len = MultiByteToWideChar(CP_ACP, 0, command_line, -1,
209 NULL, 0);
210 wsCommandLine = HeapAlloc(GetProcessHeap(), 0,
211 len * sizeof(WCHAR));
212 if (wsCommandLine)
213 MultiByteToWideChar(CP_ACP, 0, command_line, -1,
214 wsCommandLine, len);
216 else
218 wsCommandLine = EmptyLine;
221 else
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]);
230 else
232 char *DllName = argv[i];
233 int res = 0;
235 DllFound = TRUE;
236 if (!CallInstall || (CallInstall && CallRegister))
238 if(Unregister)
239 res = UnregisterDll(DllName);
240 else
241 res = RegisterDll(DllName);
244 if (res)
245 return res;
247 if (CallInstall)
249 res = InstallDll(!Unregister, DllName, wsCommandLine);
252 return res;
256 if (!DllFound)
258 if(!Silent)
259 return Usage();
260 else
261 return -1;
264 return 0;