ReactOS  0.4.14-dev-77-gd9e7c48
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 }
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
smooth NULL
Definition: ftsmooth.c:416
static char argv0[MAX_PATH]
Definition: shlexec.c:56
Definition: name.c:36
GLuint const GLchar * name
Definition: glext.h:6031

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

Referenced by LoadLibraryList(), main(), ReportLastError(), and usage().

◆ getinput()

long getinput ( char buf,
int  buflen 
)

Definition at line 59 of file loadlib.c.

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

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 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
size_t __cdecl mbstowcs(_Out_writes_opt_z_(_MaxCount) wchar_t *_Dest, _In_z_ const char *_Source, _In_ size_t _MaxCount)
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define LoadLibraryW(x)
Definition: compat.h:404
smooth NULL
Definition: ftsmooth.c:416
DWORD ReportLastError(void)
Definition: loadlib.c:67
#define FreeLibrary(x)
Definition: compat.h:405
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
void dprintf(char *fmt,...)
Definition: loadlib.c:48
DWORD LoadLibraryList(char **libnames, int counter, BOOL bUseAnsi)
Definition: loadlib.c:113
BOOL bUseAnsi
Definition: loadlib.c:37
HMODULE hModule
Definition: animate.c:44

Referenced by main().

◆ main()

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

hosttype.c Copyright (C) 2002 by Brian Palmer brian.nosp@m.p@sg.nosp@m.inet..nosp@m.com

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) {
176  recursive_flagged = 1;
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
#define TRUE
Definition: types.h:120
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:48
BOOL debug_flagged
Definition: loadlib.c:40
int WINAPI lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:42
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
GLuint buffer
Definition: glext.h:5915
BOOL recursive_flagged
Definition: loadlib.c:42
#define argv
Definition: mplay32.c:18
HANDLE InputHandle
Definition: loadlib.c:45
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 APP_VERSION
Definition: loadlib.c:29
#define TARGET
Definition: loadlib.c:36
#define STD_INPUT_HANDLE
Definition: winbase.h:264
#define MAX_LIBS
Definition: loadlib.c:30
int usage(const char *appName)
Definition: loadlib.c:99
long getinput(char *buf, int buflen)
Definition: loadlib.c:59
GLenum GLsizei len
Definition: glext.h:6722
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
BOOL loop_flagged
Definition: loadlib.c:41
void dprintf(char *fmt,...)
Definition: loadlib.c:48
HANDLE OutputHandle
Definition: loadlib.c:44
BOOL verbose_flagged
Definition: loadlib.c:39
const char * appName(const char *argv0)
Definition: loadlib.c:89
DWORD LoadLibraryList(char **libnames, int counter, BOOL bUseAnsi)
Definition: loadlib.c:113
GLuint64EXT * result
Definition: glext.h:11304
#define memset(x, y, z)
Definition: compat.h:39
BOOL bUseAnsi
Definition: loadlib.c:37

◆ 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) {
83  LocalFree(msg);
84  }
85  }
86  return dwError;
87 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LANG_NEUTRAL
Definition: nls.h:22
DWORD WINAPI FormatMessageA(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:483
#define SUBLANG_DEFAULT
Definition: nls.h:168
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
unsigned long DWORD
Definition: ntddk_ex.h:95
void dprintf(char *fmt,...)
Definition: loadlib.c:48
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
signed char * PSTR
Definition: retypes.h:7
#define msg(x)
Definition: auth_time.c:54
#define MAKELANGID(p, s)
Definition: nls.h:15

Referenced by LoadLibraryList().

◆ 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 }
#define TARGET
Definition: loadlib.c:36
void dprintf(char *fmt,...)
Definition: loadlib.c:48
const char * appName(const char *argv0)
Definition: loadlib.c:89

Referenced by main().

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().