ReactOS 0.4.15-dev-7842-g558ab78
loadlib.c
Go to the documentation of this file.
1/*
2 * ReactOS test program -
3 *
4 * loadlib.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
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.
12 *
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.
17 *
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.
21 */
22
23#include <windows.h>
24#include "loadlib.h"
25#include <string.h>
26#include <stdlib.h>
27#include <wchar.h>
28
29#define APP_VERSION 1
30#define MAX_LIBS 25
31
32#ifdef UNICODE
33#define TARGET "UNICODE"
35#else
36#define TARGET "MBCS"
38#endif
43
46
47
48void dprintf(char* fmt, ...)
49{
51 char buffer[255];
52
56 va_end(args);
57}
58
59long getinput(char* buf, int buflen)
60{
62
64 return (long)result;
65}
66
68{
69 DWORD dwError = GetLastError();
70 if (dwError != ERROR_SUCCESS) {
71 PSTR msg = NULL;
73 0, dwError, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PSTR)&msg, 0, NULL)) {
74 if (msg != NULL) {
75 dprintf("ReportLastError() %d - %s\n", dwError, msg);
76 } else {
77 dprintf("ERROR: ReportLastError() %d - returned TRUE but with no msg string!\n", dwError);
78 }
79 } else {
80 dprintf("ReportLastError() %d - unknown error\n", dwError);
81 }
82 if (msg != NULL) {
84 }
85 }
86 return dwError;
87}
88
89const char* appName(const char* argv0)
90{
91 const char* name;
92
93 name = (const char*)strrchr(argv0, '\\');
94 if (name != NULL)
95 return name + 1;
96 return argv0;
97}
98
99int usage(const char* appName)
100{
101 dprintf("USAGE: %s libname [libname ...] [unicode]|[ansi] [loop][recurse]\n", appName);
102 dprintf("\tWhere libname(s) is one or more libraries to load.\n");
103 dprintf("\t[unicode] - perform tests using UNICODE api calls\n");
104 dprintf("\t[ansi] - perform tests using ANSI api calls\n");
105 dprintf("\t default is %s\n", TARGET);
106 dprintf("\t[loop] - run test process in continuous loop\n");
107 dprintf("\t[recurse] - load libraries recursively rather than sequentually\n");
108 dprintf("\t[debug] - enable debug mode (unused)\n");
109 dprintf("\t[verbose] - enable verbose output (unused)\n");
110 return 0;
111}
112
114{
116
117 dprintf("Attempting to LoadLibrary");
118 if (bUseAnsi) {
119 dprintf("A(%s) - ", *libnames);
120 hModule = LoadLibraryA(*libnames);
121 } else {
122 int len;
123 wchar_t libnameW[500];
124 len = mbstowcs(libnameW, *libnames, strlen(*libnames));
125 if (len) {
126 libnameW[len] = L'\0';
127 dprintf("W(%S) - ", libnameW);
128 hModule = LoadLibraryW(libnameW);
129 } else {
131 }
132 }
133 if (hModule == NULL) {
134 dprintf("\nERROR: failed to obtain handle to module %s - %x\n", *libnames, hModule);
135 return ReportLastError();
136 }
137 dprintf("%x\n", hModule);
138
139 if (counter--) {
140 LoadLibraryList(++libnames, counter, bUseAnsi);
141 }
142
143 if (!FreeLibrary(hModule)) {
144 dprintf("ERROR: failed to free module %s - %x\n", *libnames, hModule);
145 return ReportLastError();
146 } else {
147 dprintf("FreeLibrary(%x) - successfull.\n", hModule);
148 }
149 return 0L;
150}
151
152int __cdecl main(int argc, char* argv[])
153{
154 char* libs[MAX_LIBS];
155 int lib_count = 0;
156 int result = 0;
157 int i = 0;
158
159 AllocConsole();
162
163 dprintf("%s application - build %03d (default: %s)\n", appName(argv[0]), APP_VERSION, TARGET);
164 if (argc < 2) {
165 /*return */usage(appName(argv[0]));
166 }
167 memset(libs, 0, sizeof(libs));
168 for (i = 1; i < argc; i++) {
169 if (lstrcmpiA(argv[i], "ansi") == 0) {
170 bUseAnsi = TRUE;
171 } else if (lstrcmpiA(argv[i], "unicode") == 0) {
172 bUseAnsi = FALSE;
173 } else if (lstrcmpiA(argv[i], "loop") == 0) {
174 loop_flagged = 1;
175 } else if (lstrcmpiA(argv[i], "recurse") == 0) {
177 } else if (lstrcmpiA(argv[i], "verbose") == 0) {
178 verbose_flagged = 1;
179 } else if (lstrcmpiA(argv[i], "debug") == 0) {
180 debug_flagged = 1;
181 } else {
182 if (lib_count < MAX_LIBS) {
183 libs[lib_count] = argv[i];
184 ++lib_count;
185 }
186 }
187 }
188 if (lib_count) {
189 do {
190 if (recursive_flagged) {
191 result = LoadLibraryList(libs, lib_count - 1, bUseAnsi);
192 } else {
193 for (i = 0; i < lib_count; i++) {
194 result = LoadLibraryList(&libs[i], 0, bUseAnsi);
195 //if (result != 0) break;
196 }
197 }
198 } while (loop_flagged);
199 } else {
200 int len;
201 char buffer[500];
202 do {
203 dprintf("\nEnter library name to attempt loading: ");
204 len = getinput(buffer, sizeof(buffer) - 1);
205 if (len > 2) {
206 char* buf = buffer;
207 buffer[len-2] = '\0';
209 } else break;
210 } while (!result && len);
211 }
212 dprintf("finished\n");
213 return result;
214}
215
216
217#ifdef _NOCRT
218char* args[] = { "loadlib.exe", "advapi32.dll", "user32.dll", "recurse"};
219int __cdecl mainCRTStartup(void)
220{
221 return main(3, args);
222}
223#endif /*__GNUC__*/
static int argc
Definition: ServiceArgs.c:12
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define __cdecl
Definition: accygwin.h:79
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define msg(x)
Definition: auth_time.c:54
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:74
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HMODULE hModule
Definition: animate.c:44
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleA(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1468
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleA(IN HANDLE hConsoleInput, OUT LPVOID lpBuffer, IN DWORD nNumberOfCharsToRead, OUT LPDWORD lpNumberOfCharsRead, IN PCONSOLE_READCONSOLE_CONTROL pInputControl OPTIONAL)
Definition: readwrite.c:1195
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
DWORD WINAPI FormatMessageA(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:483
int main()
Definition: test.c:6
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
GLuint64EXT * result
Definition: glext.h:11304
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
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
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
size_t __cdecl mbstowcs(_Out_writes_opt_z_(_MaxCount) wchar_t *_Dest, _In_z_ const char *_Source, _In_ size_t _MaxCount)
HANDLE InputHandle
Definition: loadlib.c:45
#define MAX_LIBS
Definition: loadlib.c:30
long getinput(char *buf, int buflen)
Definition: loadlib.c:59
BOOL loop_flagged
Definition: loadlib.c:41
BOOL bUseAnsi
Definition: loadlib.c:37
DWORD LoadLibraryList(char **libnames, int counter, BOOL bUseAnsi)
Definition: loadlib.c:113
#define APP_VERSION
Definition: loadlib.c:29
BOOL debug_flagged
Definition: loadlib.c:40
#define TARGET
Definition: loadlib.c:36
HANDLE OutputHandle
Definition: loadlib.c:44
const char * appName(const char *argv0)
Definition: loadlib.c:89
BOOL recursive_flagged
Definition: loadlib.c:42
DWORD ReportLastError(void)
Definition: loadlib.c:67
BOOL verbose_flagged
Definition: loadlib.c:39
int WINAPI lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:42
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
#define dprintf
Definition: regdump.c:33
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define memset(x, y, z)
Definition: compat.h:39
#define args
Definition: format.c:66
static char argv0[MAX_PATH]
Definition: shlexec.c:49
Definition: match.c:390
Definition: dsound.c:943
Definition: name.c:39
char * PSTR
Definition: typedefs.h:51
#define mainCRTStartup
Definition: wcrtexe.c:10
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define STD_INPUT_HANDLE
Definition: winbase.h:267
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
int WINAPI wvsprintfA(_Out_ LPSTR, _In_ _Printf_format_string_ LPCSTR, _In_ va_list arglist)