ReactOS 0.4.15-dev-7958-gcd0bb1a
regsvr32.c File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <ole2.h>
#include <tchar.h>
#include "resource.h"
Include dependency graph for regsvr32.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define EXITCODE_SUCCESS   0
 
#define EXITCODE_PARAMERROR   1
 
#define EXITCODE_LOADERROR   3
 
#define EXITCODE_NOENTRY   4
 
#define EXITCODE_FAILURE   5
 
#define tszDllRegister   szDllRegister
 
#define tszDllUnregister   szDllUnregister
 
#define tszDllInstall   szDllInstall
 
#define CommandLineToArgv   CommandLineToArgvT
 
#define FreeConvertedWideChar(lpwString)   free(lpwString)
 

Typedefs

typedef HRESULT(WINAPIDLLREGISTER) (void)
 
typedef HRESULT(WINAPIDLLINSTALL) (BOOL bInstall, LPWSTR lpwCmdLine)
 

Functions

LPTSTR *WINAPI CommandLineToArgvT (LPCTSTR lpCmdLine, int *lpArgc)
 
LPWSTR ConvertToWideChar (LPCSTR lpString)
 
void DisplayMessage (BOOL bConsole, BOOL bSilent, LPCTSTR lpMessage, LPCTSTR lpTitle, UINT uType)
 
int WINAPI _tWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
 

Variables

LPCSTR szDllRegister = "DllRegisterServer"
 
LPCSTR szDllUnregister = "DllUnregisterServer"
 
LPCSTR szDllInstall = "DllInstall"
 
LPCTSTR ModuleTitle = _T("RegSvr32")
 
TCHAR UsageMessage [RC_STRING_MAX_SIZE]
 
TCHAR NoDllSpecified [RC_STRING_MAX_SIZE]
 
TCHAR InvalidFlag [RC_STRING_MAX_SIZE]
 
TCHAR SwitchN_NoI [RC_STRING_MAX_SIZE]
 
TCHAR DllNotLoaded [RC_STRING_MAX_SIZE]
 
TCHAR MissingEntry [RC_STRING_MAX_SIZE]
 
TCHAR FailureMessage [RC_STRING_MAX_SIZE]
 
TCHAR SuccessMessage [RC_STRING_MAX_SIZE]
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 25 of file regsvr32.c.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 26 of file regsvr32.c.

◆ CommandLineToArgv

#define CommandLineToArgv   CommandLineToArgvT

Definition at line 78 of file regsvr32.c.

◆ EXITCODE_FAILURE

#define EXITCODE_FAILURE   5

Definition at line 40 of file regsvr32.c.

◆ EXITCODE_LOADERROR

#define EXITCODE_LOADERROR   3

Definition at line 38 of file regsvr32.c.

◆ EXITCODE_NOENTRY

#define EXITCODE_NOENTRY   4

Definition at line 39 of file regsvr32.c.

◆ EXITCODE_PARAMERROR

#define EXITCODE_PARAMERROR   1

Definition at line 37 of file regsvr32.c.

◆ EXITCODE_SUCCESS

#define EXITCODE_SUCCESS   0

Definition at line 36 of file regsvr32.c.

◆ FreeConvertedWideChar

#define FreeConvertedWideChar (   lpwString)    free(lpwString)

Definition at line 236 of file regsvr32.c.

◆ tszDllInstall

#define tszDllInstall   szDllInstall

Definition at line 52 of file regsvr32.c.

◆ tszDllRegister

#define tszDllRegister   szDllRegister

Definition at line 50 of file regsvr32.c.

◆ tszDllUnregister

#define tszDllUnregister   szDllUnregister

Definition at line 51 of file regsvr32.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 24 of file regsvr32.c.

Typedef Documentation

◆ DLLINSTALL

typedef HRESULT(WINAPI * DLLINSTALL) (BOOL bInstall, LPWSTR lpwCmdLine)

Definition at line 34 of file regsvr32.c.

◆ DLLREGISTER

typedef HRESULT(WINAPI * DLLREGISTER) (void)

Definition at line 33 of file regsvr32.c.

Function Documentation

◆ _tWinMain()

int WINAPI _tWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPTSTR  lpCmdLine,
int  nCmdShow 
)

Definition at line 247 of file regsvr32.c.

253{
254 int argc;
255 LPTSTR *argv;
256 LPTSTR lptDllName,lptDllCmdLine,lptMsgBuffer;
257 LPCTSTR lptFuncName;
258 LPCSTR lpFuncName;
259 LPWSTR lpwDllCmdLine;
260 BOOL bUnregister,bSilent,bConsole,bInstall,bNoRegister;
261 UINT nDllCount, fuOldErrorMode;
262 HMODULE hDll;
263 DLLREGISTER fnDllRegister;
264 DLLINSTALL fnDllInstall;
265 HRESULT hResult;
266 DWORD dwErr;
267 int nRetValue,i;
268
269 // Get Langues msg
274
279
280 // Get command-line in argc-argv format
282
283 // Initialize variables
284 lptFuncName = 0;
285 lptDllCmdLine = 0;
286 nDllCount = 0;
287 bUnregister = FALSE;
288 bSilent = FALSE;
289 bConsole = FALSE;
290 bInstall = FALSE;
291 bNoRegister = FALSE;
292
293 // Find all arguments starting with a slash (/)
294 for (i = 1; i < argc; i++) {
295 if (*argv[i] == _T('/') || *argv[i] == '-') {
296 switch (argv[i][1]) {
297 case _T('u'):
298 case _T('U'):
299 bUnregister = TRUE;
300 break;
301 case _T('s'):
302 case _T('S'):
303 bSilent = TRUE;
304 break;
305 case _T('c'):
306 case _T('C'):
307 bConsole = TRUE;
308 break;
309 case _T('i'):
310 case _T('I'):
311 bInstall = TRUE;
312 lptDllCmdLine = argv[i];
313 while (*lptDllCmdLine != 0 && *lptDllCmdLine != _T(':'))
314 lptDllCmdLine++;
315 if (*lptDllCmdLine == _T(':'))
316 lptDllCmdLine++;
317 break;
318 case _T('n'):
319 case _T('N'):
320 bNoRegister = TRUE;
321 break;
322 default:
323 if (!lptFuncName)
324 lptFuncName = argv[i];
325 }
326 }
327 else {
328 nDllCount++;
329 }
330 }
331
332 // An unrecognized flag was used, display a message and show available options
333
334 if (lptFuncName) {
335 lptMsgBuffer = (LPTSTR)malloc((_tcslen(UsageMessage) - 2 + _tcslen(InvalidFlag) - 2 + _tcslen(lptFuncName) + 1) * sizeof(TCHAR));
336 _stprintf(lptMsgBuffer + (_tcslen(UsageMessage) - 2),InvalidFlag,lptFuncName);
337 _stprintf(lptMsgBuffer,UsageMessage,lptMsgBuffer + (_tcslen(UsageMessage) - 2));
338 DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
339 free(lptMsgBuffer);
341 return EXITCODE_PARAMERROR;
342 }
343
344 // /n was used without /i, display a message and show available options
345 if (bNoRegister && (!bInstall)) {
346 lptMsgBuffer = (LPTSTR)malloc((_tcslen(UsageMessage) - 2 + _tcslen(SwitchN_NoI) + 1) * sizeof(TCHAR));
347 _stprintf(lptMsgBuffer,UsageMessage,SwitchN_NoI);
348 DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
349 free(lptMsgBuffer);
351 return EXITCODE_PARAMERROR;
352 }
353
354 // No dll was specified, display a message and show available options
355 if (nDllCount == 0) {
356 lptMsgBuffer = (LPTSTR)malloc((_tcslen(UsageMessage) - 2 + _tcslen(NoDllSpecified) + 1) * sizeof(TCHAR));
358 DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
359 free(lptMsgBuffer);
361 return EXITCODE_PARAMERROR;
362 }
363
364 nRetValue = EXITCODE_SUCCESS;
365 if (!bUnregister) {
366 lpFuncName = szDllRegister;
367 lptFuncName = tszDllRegister;
368 }
369 else {
370 lpFuncName = szDllUnregister;
371 lptFuncName = tszDllUnregister;
372 }
373
374 if (lptDllCmdLine)
375 lpwDllCmdLine = ConvertToWideChar(lptDllCmdLine);
376 else
377 lpwDllCmdLine = 0;
378
379 // Initialize OLE32 before attempting to register the
380 // dll. Some dll's require this to register properly
381 OleInitialize(0);
382
383 // (Un)register every dll whose filename was passed in the command-line string
384 for (i = 1; i < argc && nRetValue == EXITCODE_SUCCESS; i++) {
385 // Arguments that do not start with a slash (/) are filenames
386 if (*argv[i] != _T('/')) {
387 lptDllName = argv[i];
388
389 fuOldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
390 // Everything is all setup, so load the dll now
391 hDll = LoadLibraryEx(lptDllName,0,LOAD_WITH_ALTERED_SEARCH_PATH);
392 if (hDll) {
393 SetErrorMode(fuOldErrorMode);
394 if (!bNoRegister) {
395 // Get the address of DllRegisterServer or DllUnregisterServer
396 fnDllRegister = (DLLREGISTER)GetProcAddress(hDll,lpFuncName);
397 if (fnDllRegister) {
398 // If the function exists, call it
399 hResult = fnDllRegister();
400 if (hResult == S_OK) {
401 // (Un)register succeeded, display a message
402 lptMsgBuffer = (LPTSTR)malloc((_tcslen(SuccessMessage) - 4 + _tcslen(lptFuncName) + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
403 _stprintf(lptMsgBuffer,SuccessMessage,lptFuncName,lptDllName);
404 DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONINFORMATION);
405 }
406 else {
407 // (Un)register failed, display a message
408 lptMsgBuffer = (LPTSTR)malloc((_tcslen(FailureMessage) + _tcslen(lptFuncName) + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
409 _stprintf(lptMsgBuffer,FailureMessage,lptFuncName,lptDllName,hResult);
410 DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
411 }
412 free(lptMsgBuffer);
413 if (hResult != S_OK)
414 nRetValue = EXITCODE_FAILURE;
415 }
416 else {
417 FreeLibrary(hDll);
418 // Dll(Un)register was not found, display an error message
419 lptMsgBuffer = (LPTSTR)malloc((_tcslen(MissingEntry) - 8 + _tcslen(lptFuncName) * 2 + _tcslen(lptDllName) * 2 + 1) * sizeof(TCHAR));
420 _stprintf(lptMsgBuffer,MissingEntry,lptDllName,lptFuncName,lptFuncName,lptDllName);
421 DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
422 free(lptMsgBuffer);
423 nRetValue = EXITCODE_NOENTRY;
424 }
425 }
426
427 if (bInstall && nRetValue == EXITCODE_SUCCESS) {
428 // Get the address of DllInstall
429 fnDllInstall = (DLLINSTALL)GetProcAddress(hDll,szDllInstall);
430 if (fnDllInstall) {
431 // If the function exists, call it
432 if (!bUnregister)
433 hResult = fnDllInstall(1,lpwDllCmdLine);
434 else
435 hResult = fnDllInstall(0,lpwDllCmdLine);
436 if (hResult == S_OK) {
437 // (Un)install succeeded, display a message
438 lptMsgBuffer = (LPTSTR)malloc((_tcslen(SuccessMessage) - 4 + _tcslen(tszDllInstall) + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
439 _stprintf(lptMsgBuffer,SuccessMessage,tszDllInstall,lptDllName);
440 DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONINFORMATION);
441 }
442 else {
443 // (Un)install failed, display a message
444 lptMsgBuffer = (LPTSTR)malloc((_tcslen(FailureMessage) + _tcslen(tszDllInstall) + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
445 _stprintf(lptMsgBuffer,FailureMessage,tszDllInstall,lptDllName,hResult);
446 DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
447 }
448 free(lptMsgBuffer);
449 if (hResult != S_OK)
450 nRetValue = EXITCODE_FAILURE;
451 }
452 else {
453 // DllInstall was not found, display an error message
454 lptMsgBuffer = (LPTSTR)malloc((_tcslen(MissingEntry) - 8 + _tcslen(tszDllInstall) * 2 + _tcslen(lptDllName) * 2 + 1) * sizeof(TCHAR));
455 _stprintf(lptMsgBuffer,MissingEntry,lptDllName,tszDllInstall,tszDllInstall,lptDllName);
456 DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
457 free(lptMsgBuffer);
458 nRetValue = EXITCODE_NOENTRY;
459 }
460 }
461
462 // The dll function has finished executing, so unload it
463 FreeLibrary(hDll);
464 }
465 else {
466 // The dll could not be loaded; display an error message
468 SetErrorMode(fuOldErrorMode);
469 lptMsgBuffer = (LPTSTR)malloc((_tcslen(DllNotLoaded) + 2 + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
470 _stprintf(lptMsgBuffer,DllNotLoaded,lptDllName,dwErr);
471 DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
472 free(lptMsgBuffer);
473 nRetValue = EXITCODE_LOADERROR;
474 }
475 }
476 }
477
478 if (lpwDllCmdLine)
479 FreeConvertedWideChar(lpwDllCmdLine);
482 return nRetValue;
483}
static int argc
Definition: ServiceArgs.c:12
#define RC_STRING_MAX_SIZE
Definition: resource.h:3
DWORD dwErr
Definition: service.c:36
#define IDS_SwitchN_NoI
Definition: resource.h:7
#define IDS_DllNotLoaded
Definition: resource.h:8
#define IDS_MissingEntry
Definition: resource.h:9
#define IDS_InvalidFlag
Definition: resource.h:6
#define IDS_SuccessMessage
Definition: resource.h:11
#define IDS_UsageMessage
Definition: resource.h:4
#define IDS_FailureMessage
Definition: resource.h:10
#define IDS_NoDllSpecified
Definition: resource.h:5
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
UINT WINAPI SetErrorMode(IN UINT uMode)
Definition: except.c:751
HRESULT WINAPI DECLSPEC_HOTPATCH OleInitialize(LPVOID reserved)
Definition: ole2.c:169
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
Definition: ole2.c:230
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define S_OK
Definition: intsafe.h:52
#define _stprintf
Definition: utility.h:124
#define argv
Definition: mplay32.c:18
unsigned int UINT
Definition: ndis.h:50
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
TCHAR SwitchN_NoI[RC_STRING_MAX_SIZE]
Definition: regsvr32.c:62
TCHAR DllNotLoaded[RC_STRING_MAX_SIZE]
Definition: regsvr32.c:63
#define EXITCODE_NOENTRY
Definition: regsvr32.c:39
#define FreeConvertedWideChar(lpwString)
Definition: regsvr32.c:236
TCHAR UsageMessage[RC_STRING_MAX_SIZE]
Definition: regsvr32.c:59
#define CommandLineToArgv
Definition: regsvr32.c:78
TCHAR InvalidFlag[RC_STRING_MAX_SIZE]
Definition: regsvr32.c:61
#define EXITCODE_PARAMERROR
Definition: regsvr32.c:37
TCHAR FailureMessage[RC_STRING_MAX_SIZE]
Definition: regsvr32.c:65
HRESULT(WINAPI * DLLREGISTER)(void)
Definition: regsvr32.c:33
#define EXITCODE_LOADERROR
Definition: regsvr32.c:38
TCHAR SuccessMessage[RC_STRING_MAX_SIZE]
Definition: regsvr32.c:66
TCHAR MissingEntry[RC_STRING_MAX_SIZE]
Definition: regsvr32.c:64
#define tszDllInstall
Definition: regsvr32.c:52
LPCTSTR ModuleTitle
Definition: regsvr32.c:57
#define EXITCODE_SUCCESS
Definition: regsvr32.c:36
void DisplayMessage(BOOL bConsole, BOOL bSilent, LPCTSTR lpMessage, LPCTSTR lpTitle, UINT uType)
Definition: regsvr32.c:239
TCHAR NoDllSpecified[RC_STRING_MAX_SIZE]
Definition: regsvr32.c:60
LPCSTR szDllRegister
Definition: regsvr32.c:42
#define EXITCODE_FAILURE
Definition: regsvr32.c:40
LPWSTR ConvertToWideChar(LPCSTR lpString)
Definition: regsvr32.c:223
LPCSTR szDllInstall
Definition: regsvr32.c:44
#define tszDllUnregister
Definition: regsvr32.c:51
HRESULT(WINAPI * DLLINSTALL)(BOOL bInstall, LPWSTR lpwCmdLine)
Definition: regsvr32.c:34
#define tszDllRegister
Definition: regsvr32.c:50
LPCSTR szDllUnregister
Definition: regsvr32.c:43
#define _T(x)
Definition: vfdio.h:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define LoadLibraryEx
Definition: winbase.h:3863
#define GetCommandLine
Definition: winbase.h:3799
#define GetModuleHandle
Definition: winbase.h:3827
#define LOAD_WITH_ALTERED_SEARCH_PATH
Definition: winbase.h:344
#define MB_ICONEXCLAMATION
Definition: winuser.h:785
#define LoadString
Definition: winuser.h:5819
#define MB_ICONINFORMATION
Definition: winuser.h:802
char TCHAR
Definition: xmlstorage.h:189
const char * LPCSTR
Definition: xmlstorage.h:183
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define _tcslen
Definition: xmlstorage.h:198

◆ CommandLineToArgvT()

LPTSTR *WINAPI CommandLineToArgvT ( LPCTSTR  lpCmdLine,
int lpArgc 
)

Definition at line 80 of file regsvr32.c.

81{
82 HGLOBAL hargv;
83 LPTSTR *argv, lpSrc, lpDest, lpArg;
84 int argc, nBSlash;
85 BOOL bInQuotes;
86
87 // If null was passed in for lpCmdLine, there are no arguments
88 if (!lpCmdLine) {
89 if (lpArgc)
90 *lpArgc = 0;
91 return 0;
92 }
93
94 lpSrc = (LPTSTR)lpCmdLine;
95 // Skip spaces at beginning
96 while (*lpSrc == _T(' ') || *lpSrc == _T('\t'))
97 lpSrc++;
98
99 // If command-line starts with null, there are no arguments
100 if (*lpSrc == 0) {
101 if (lpArgc)
102 *lpArgc = 0;
103 return 0;
104 }
105
106 lpArg = lpSrc;
107 argc = 0;
108 nBSlash = 0;
109 bInQuotes = FALSE;
110
111 // Count the number of arguments
112 while (1) {
113 if (*lpSrc == 0 || ((*lpSrc == _T(' ') || *lpSrc == _T('\t')) && !bInQuotes)) {
114 // Whitespace not enclosed in quotes signals the start of another argument
115 argc++;
116
117 // Skip whitespace between arguments
118 while (*lpSrc == _T(' ') || *lpSrc == _T('\t'))
119 lpSrc++;
120 if (*lpSrc == 0)
121 break;
122 nBSlash = 0;
123 continue;
124 }
125 else if (*lpSrc == _T('\\')) {
126 // Count consecutive backslashes
127 nBSlash++;
128 }
129 else if (*lpSrc == _T('\"') && !(nBSlash & 1)) {
130 // Open or close quotes
131 bInQuotes = !bInQuotes;
132 nBSlash = 0;
133 }
134 else {
135 // Some other character
136 nBSlash = 0;
137 }
138 lpSrc++;
139 }
140
141 // Allocate space the same way as CommandLineToArgvW for compatibility
142 hargv = GlobalAlloc(0, argc * sizeof(LPTSTR) + (_tcslen(lpArg) + 1) * sizeof(TCHAR));
143 argv = (LPTSTR *)GlobalLock(hargv);
144
145 if (!argv) {
146 // Memory allocation failed
147 if (lpArgc)
148 *lpArgc = 0;
149 return 0;
150 }
151
152 lpSrc = lpArg;
153 lpDest = lpArg = (LPTSTR)(argv + argc);
154 argc = 0;
155 nBSlash = 0;
156 bInQuotes = FALSE;
157
158 // Fill the argument array
159 while (1) {
160 if (*lpSrc == 0 || ((*lpSrc == _T(' ') || *lpSrc == _T('\t')) && !bInQuotes)) {
161 // Whitespace not enclosed in quotes signals the start of another argument
162 // Null-terminate argument
163 *lpDest++ = 0;
164 argv[argc++] = lpArg;
165
166 // Skip whitespace between arguments
167 while (*lpSrc == _T(' ') || *lpSrc == _T('\t'))
168 lpSrc++;
169 if (*lpSrc == 0)
170 break;
171 lpArg = lpDest;
172 nBSlash = 0;
173 continue;
174 }
175 else if (*lpSrc == _T('\\')) {
176 *lpDest++ = _T('\\');
177 lpSrc++;
178
179 // Count consecutive backslashes
180 nBSlash++;
181 }
182 else if (*lpSrc == _T('\"')) {
183 if (!(nBSlash & 1)) {
184 // If an even number of backslashes are before the quotes,
185 // the quotes don't go in the output
186 lpDest -= nBSlash / 2;
187 bInQuotes = !bInQuotes;
188 }
189 else {
190 // If an odd number of backslashes are before the quotes,
191 // output a quote
192 lpDest -= (nBSlash + 1) / 2;
193 *lpDest++ = _T('\"');
194 }
195 lpSrc++;
196 nBSlash = 0;
197 }
198 else {
199 // Copy other characters
200 *lpDest++ = *lpSrc++;
201 nBSlash = 0;
202 }
203 }
204
205 if (lpArgc)
206 *lpArgc = argc;
207 return argv;
208}
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368

◆ ConvertToWideChar()

LPWSTR ConvertToWideChar ( LPCSTR  lpString)

Definition at line 223 of file regsvr32.c.

224{
225 LPWSTR lpwString;
226 size_t nStrLen;
227
228 nStrLen = strlen(lpString) + 1;
229
230 lpwString = (LPWSTR)malloc(nStrLen * sizeof(WCHAR));
231 MultiByteToWideChar(0,0,lpString,nStrLen,lpwString,nStrLen);
232
233 return lpwString;
234}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define MultiByteToWideChar
Definition: compat.h:110
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by _tWinMain().

◆ DisplayMessage()

void DisplayMessage ( BOOL  bConsole,
BOOL  bSilent,
LPCTSTR  lpMessage,
LPCTSTR  lpTitle,
UINT  uType 
)

Variable Documentation

◆ DllNotLoaded

TCHAR DllNotLoaded[RC_STRING_MAX_SIZE]

Definition at line 63 of file regsvr32.c.

Referenced by _tWinMain().

◆ FailureMessage

TCHAR FailureMessage[RC_STRING_MAX_SIZE]

Definition at line 65 of file regsvr32.c.

Referenced by _tWinMain().

◆ InvalidFlag

TCHAR InvalidFlag[RC_STRING_MAX_SIZE]

Definition at line 61 of file regsvr32.c.

Referenced by _tWinMain().

◆ MissingEntry

TCHAR MissingEntry[RC_STRING_MAX_SIZE]

Definition at line 64 of file regsvr32.c.

Referenced by _tWinMain().

◆ ModuleTitle

LPCTSTR ModuleTitle = _T("RegSvr32")

Definition at line 57 of file regsvr32.c.

Referenced by _tWinMain().

◆ NoDllSpecified

TCHAR NoDllSpecified[RC_STRING_MAX_SIZE]

Definition at line 60 of file regsvr32.c.

Referenced by _tWinMain().

◆ SuccessMessage

TCHAR SuccessMessage[RC_STRING_MAX_SIZE]

Definition at line 66 of file regsvr32.c.

Referenced by _tWinMain().

◆ SwitchN_NoI

TCHAR SwitchN_NoI[RC_STRING_MAX_SIZE]

Definition at line 62 of file regsvr32.c.

Referenced by _tWinMain().

◆ szDllInstall

LPCSTR szDllInstall = "DllInstall"

Definition at line 44 of file regsvr32.c.

Referenced by _tWinMain().

◆ szDllRegister

LPCSTR szDllRegister = "DllRegisterServer"

Definition at line 42 of file regsvr32.c.

Referenced by _tWinMain().

◆ szDllUnregister

LPCSTR szDllUnregister = "DllUnregisterServer"

Definition at line 43 of file regsvr32.c.

Referenced by _tWinMain().

◆ UsageMessage

TCHAR UsageMessage[RC_STRING_MAX_SIZE]

Definition at line 59 of file regsvr32.c.

Referenced by _tWinMain().