2 * ReactOS test program -
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program 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
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #define TARGET "UNICODE"
33 BOOL bUseAnsi
= FALSE
;
38 BOOL verbose_flagged
= FALSE
;
39 BOOL debug_flagged
= FALSE
;
40 BOOL loop_flagged
= FALSE
;
41 BOOL recursive_flagged
= FALSE
;
47 void dprintf(char* fmt
, ...)
53 wvsprintfA(buffer
, fmt
, args
);
54 WriteConsoleA(OutputHandle
, buffer
, lstrlenA(buffer
), NULL
, NULL
);
58 long getinput(char* buf
, int buflen
)
62 ReadConsoleA(InputHandle
, buf
, buflen
, &result
, NULL
);
66 DWORD
ReportLastError(void)
68 DWORD dwError
= GetLastError();
69 if (dwError
!= ERROR_SUCCESS
) {
71 if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
72 0, dwError
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PSTR
)&msg
, 0, NULL
)) {
74 dprintf("ReportLastError() %d - %s\n", dwError
, msg
);
76 dprintf("ERROR: ReportLastError() %d - returned TRUE but with no msg string!\n", dwError
);
79 dprintf("ReportLastError() %d - unknown error\n", dwError
);
88 const char* appName(const char* argv0
)
92 name
= (const char*)strrchr(argv0
, '\\');
98 int usage(const char* appName
)
100 dprintf("USAGE: %s libname [libname ...] [unicode]|[ansi] [loop][recurse]\n", appName
);
101 dprintf("\tWhere libname(s) is one or more libraries to load.\n");
102 dprintf("\t[unicode] - perform tests using UNICODE api calls\n");
103 dprintf("\t[ansi] - perform tests using ANSI api calls\n");
104 dprintf("\t default is %s\n", TARGET
);
105 dprintf("\t[loop] - run test process in continuous loop\n");
106 dprintf("\t[recurse] - load libraries recursively rather than sequentually\n");
107 dprintf("\t[debug] - enable debug mode (unused)\n");
108 dprintf("\t[verbose] - enable verbose output (unused)\n");
112 DWORD
LoadLibraryList(char** libnames
, int counter
, BOOL bUseAnsi
)
116 dprintf("Attempting to LoadLibrary");
118 dprintf("A(%s) - ", *libnames
);
119 hModule
= LoadLibraryA(*libnames
);
122 wchar_t libnameW
[500];
123 len
= mbstowcs(libnameW
, *libnames
, strlen(*libnames
));
125 libnameW
[len
] = L
'\0';
126 dprintf("W(%S) - ", libnameW
);
127 hModule
= LoadLibraryW(libnameW
);
129 return ERROR_INVALID_PARAMETER
;
132 if (hModule
== NULL
) {
133 dprintf("\nERROR: failed to obtain handle to module %s - %x\n", *libnames
, hModule
);
134 return ReportLastError();
136 dprintf("%x\n", hModule
);
139 LoadLibraryList(++libnames
, counter
, bUseAnsi
);
142 if (!FreeLibrary(hModule
)) {
143 dprintf("ERROR: failed to free module %s - %x\n", *libnames
, hModule
);
144 return ReportLastError();
146 dprintf("FreeLibrary(%x) - successfull.\n", hModule
);
151 int __cdecl
main(int argc
, char* argv
[])
153 char* libs
[MAX_LIBS
];
159 InputHandle
= GetStdHandle(STD_INPUT_HANDLE
);
160 OutputHandle
= GetStdHandle(STD_OUTPUT_HANDLE
);
162 dprintf("%s application - build %03d (default: %s)\n", appName(argv
[0]), APP_VERSION
, TARGET
);
164 /*return */usage(appName(argv
[0]));
166 memset(libs
, 0, sizeof(libs
));
167 for (i
= 1; i
< argc
; i
++) {
168 if (lstrcmpiA(argv
[i
], "ansi") == 0) {
170 } else if (lstrcmpiA(argv
[i
], "unicode") == 0) {
172 } else if (lstrcmpiA(argv
[i
], "loop") == 0) {
174 } else if (lstrcmpiA(argv
[i
], "recurse") == 0) {
175 recursive_flagged
= 1;
176 } else if (lstrcmpiA(argv
[i
], "verbose") == 0) {
178 } else if (lstrcmpiA(argv
[i
], "debug") == 0) {
181 if (lib_count
< MAX_LIBS
) {
182 libs
[lib_count
] = argv
[i
];
189 if (recursive_flagged
) {
190 result
= LoadLibraryList(libs
, lib_count
- 1, bUseAnsi
);
192 for (i
= 0; i
< lib_count
; i
++) {
193 result
= LoadLibraryList(&libs
[i
], 0, bUseAnsi
);
194 //if (result != 0) break;
197 } while (loop_flagged
);
202 dprintf("\nEnter library name to attempt loading: ");
203 len
= getinput(buffer
, sizeof(buffer
) - 1);
206 buffer
[len
-2] = '\0';
207 result
= LoadLibraryList(&buf
, 0, bUseAnsi
);
209 } while (!result
&& len
);
211 dprintf("finished\n");
217 char* args
[] = { "loadlib.exe", "advapi32.dll", "user32.dll", "recurse"};
218 int __cdecl
mainCRTStartup(void)
220 return main(3, args
);