ReactOS 0.4.15-dev-7961-gdcf9eb0
loadlib.c File Reference
#include <windows.h>
#include "loadlib.h"
#include <string.h>
#include <stdlib.h>
#include <wchar.h>
Include dependency graph for loadlib.c:

Go to the source code of this file.

Macros

#define APP_VERSION   1
 
#define MAX_LIBS   25
 
#define TARGET   "MBCS"
 

Functions

void dprintf (char *fmt,...)
 
long getinput (char *buf, int buflen)
 
DWORD ReportLastError (void)
 
const charappName (const char *argv0)
 
int usage (const char *appName)
 
DWORD LoadLibraryList (char **libnames, int counter, BOOL bUseAnsi)
 
int __cdecl main (int argc, char *argv[])
 

Variables

BOOL bUseAnsi = TRUE
 
BOOL verbose_flagged = FALSE
 
BOOL debug_flagged = FALSE
 
BOOL loop_flagged = FALSE
 
BOOL recursive_flagged = FALSE
 
HANDLE OutputHandle
 
HANDLE InputHandle
 

Macro Definition Documentation

◆ APP_VERSION

#define APP_VERSION   1

Definition at line 29 of file loadlib.c.

◆ MAX_LIBS

#define MAX_LIBS   25

Definition at line 30 of file loadlib.c.

◆ TARGET

#define TARGET   "MBCS"

Definition at line 36 of file loadlib.c.

Function Documentation

◆ appName()

const char * appName ( const char argv0)

Definition at line 89 of file loadlib.c.

90{
91 const char* name;
92
93 name = (const char*)strrchr(argv0, '\\');
94 if (name != NULL)
95 return name + 1;
96 return argv0;
97}
#define NULL
Definition: types.h:112
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
static char argv0[MAX_PATH]
Definition: shlexec.c:49
Definition: name.c:39

Referenced by Control_DoInterface(), Control_WndProc(), IDirectPlayLobby3AImpl_RunApplication(), load_mapi_providers(), main(), SHGetIniStringW(), SHSetIniStringW(), test_launch_app_registry(), and usage().

◆ dprintf()

void dprintf ( char fmt,
  ... 
)

Definition at line 48 of file loadlib.c.

49{
51 char buffer[255];
52
56 va_end(args);
57}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleA(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1468
GLuint buffer
Definition: glext.h:5915
HANDLE OutputHandle
Definition: loadlib.c:44
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define args
Definition: format.c:66
Definition: match.c:390
Definition: dsound.c:943
int WINAPI wvsprintfA(_Out_ LPSTR, _In_ _Printf_format_string_ LPCSTR, _In_ va_list arglist)

◆ getinput()

long getinput ( char buf,
int  buflen 
)

Definition at line 59 of file loadlib.c.

60{
62
64 return (long)result;
65}
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
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint64EXT * result
Definition: glext.h:11304
HANDLE InputHandle
Definition: loadlib.c:45

Referenced by main().

◆ LoadLibraryList()

DWORD LoadLibraryList ( char **  libnames,
int  counter,
BOOL  bUseAnsi 
)

Definition at line 113 of file loadlib.c.

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}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
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
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
GLenum GLsizei len
Definition: glext.h:6722
size_t __cdecl mbstowcs(_Out_writes_opt_z_(_MaxCount) wchar_t *_Dest, _In_z_ const char *_Source, _In_ size_t _MaxCount)
BOOL bUseAnsi
Definition: loadlib.c:37
DWORD LoadLibraryList(char **libnames, int counter, BOOL bUseAnsi)
Definition: loadlib.c:113
DWORD ReportLastError(void)
Definition: loadlib.c:67
#define L(x)
Definition: ntvdm.h:50
#define dprintf
Definition: regdump.c:33

Referenced by LoadLibraryList(), and main().

◆ main()

int __cdecl main ( int argc  ,
char argv[] 
)

Definition at line 152 of file loadlib.c.

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}
static int argc
Definition: ServiceArgs.c:12
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:74
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
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
#define MAX_LIBS
Definition: loadlib.c:30
long getinput(char *buf, int buflen)
Definition: loadlib.c:59
BOOL loop_flagged
Definition: loadlib.c:41
#define APP_VERSION
Definition: loadlib.c:29
BOOL debug_flagged
Definition: loadlib.c:40
#define TARGET
Definition: loadlib.c:36
const char * appName(const char *argv0)
Definition: loadlib.c:89
BOOL recursive_flagged
Definition: loadlib.c:42
BOOL verbose_flagged
Definition: loadlib.c:39
int WINAPI lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:42
#define argv
Definition: mplay32.c:18
#define memset(x, y, z)
Definition: compat.h:39
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define STD_INPUT_HANDLE
Definition: winbase.h:267

◆ ReportLastError()

DWORD ReportLastError ( void  )

Definition at line 67 of file loadlib.c.

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}
#define msg(x)
Definition: auth_time.c:54
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD WINAPI FormatMessageA(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:483
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_DEFAULT
Definition: nls.h:168
char * PSTR
Definition: typedefs.h:51
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

Referenced by Control(), Create(), Delete(), EnumDepend(), EnumServices(), GetDisplayName(), GetKeyName(), LoadLibraryList(), QueryConfig(), QueryDescription(), QueryFailure(), QueryService(), SdSet(), SdShow(), SetConfig(), SetDescription(), SetFailure(), and Start().

◆ usage()

int usage ( const char appName)

Definition at line 99 of file loadlib.c.

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}

Variable Documentation

◆ bUseAnsi

BOOL bUseAnsi = TRUE

Definition at line 37 of file loadlib.c.

Referenced by LoadLibraryList(), and main().

◆ debug_flagged

BOOL debug_flagged = FALSE

Definition at line 40 of file loadlib.c.

Referenced by main().

◆ InputHandle

HANDLE InputHandle

Definition at line 45 of file loadlib.c.

Referenced by getinput(), and main().

◆ loop_flagged

BOOL loop_flagged = FALSE

Definition at line 41 of file loadlib.c.

Referenced by main().

◆ OutputHandle

HANDLE OutputHandle

Definition at line 44 of file loadlib.c.

Referenced by dprintf(), and main().

◆ recursive_flagged

BOOL recursive_flagged = FALSE

Definition at line 42 of file loadlib.c.

Referenced by main().

◆ verbose_flagged

BOOL verbose_flagged = FALSE

Definition at line 39 of file loadlib.c.

Referenced by main().