2002-10-16 06:21:38 +04:00
|
|
|
#ifndef WIN32
|
|
|
|
# error This test is specific to Windows/cygwin/mingw. Turn back now!
|
|
|
|
#endif
|
|
|
|
|
2002-10-15 00:43:33 +04:00
|
|
|
#include <windows.h>
|
2002-10-15 00:34:13 +04:00
|
|
|
#include <stdio.h>
|
2002-10-16 08:40:21 +04:00
|
|
|
#include <stdlib.h>
|
2002-10-15 00:34:13 +04:00
|
|
|
#define MAIN_DLL_EXPORT
|
|
|
|
#include "main.h"
|
|
|
|
|
2002-10-15 00:43:33 +04:00
|
|
|
MAINAPI const char *version_string = "uselib-test6-1.0";
|
2002-10-15 00:34:13 +04:00
|
|
|
|
2002-10-15 00:43:33 +04:00
|
|
|
MAINAPI int register_module (const char *name)
|
2002-10-15 00:34:13 +04:00
|
|
|
{
|
|
|
|
printf ("register_module was called by module '%s'\n", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-15 00:43:33 +04:00
|
|
|
void print_last_error (char *fmtstring)
|
|
|
|
{
|
|
|
|
LPVOID lpMsgBuf;
|
|
|
|
FormatMessage(
|
|
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL,
|
|
|
|
GetLastError(),
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
|
|
|
(LPTSTR) &lpMsgBuf,
|
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
printf (fmtstring, (char*)lpMsgBuf);
|
|
|
|
LocalFree (lpMsgBuf);
|
|
|
|
}
|
|
|
|
|
2002-10-15 00:34:13 +04:00
|
|
|
int load_module (const char *fmt, const char *name)
|
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
sprintf (buf, fmt, name);
|
|
|
|
printf ("loading module from %s\n", buf);
|
2002-10-15 00:43:33 +04:00
|
|
|
HMODULE handle = LoadLibrary(buf);
|
|
|
|
printf ("handle is 0x%p\n", handle);
|
2002-10-15 00:34:13 +04:00
|
|
|
if (!handle) {
|
2002-10-15 00:43:33 +04:00
|
|
|
print_last_error ("LoadLibrary failed: %s\n");
|
2002-10-15 00:34:13 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2002-10-15 00:43:33 +04:00
|
|
|
modload_func func = (modload_func) GetProcAddress (handle, "module_init");
|
|
|
|
printf ("module_init function is at 0x%p\n", func);
|
2002-10-15 00:34:13 +04:00
|
|
|
if (func != NULL) {
|
|
|
|
printf ("Calling module_init\n");
|
|
|
|
(*func)();
|
|
|
|
} else {
|
2002-10-15 00:43:33 +04:00
|
|
|
print_last_error ("GetProcAddress failed: %s\n");
|
2002-10-15 00:34:13 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
printf ("start\n");
|
|
|
|
printf ("loading module1\n");
|
|
|
|
// try to load module1
|
2002-10-15 00:43:33 +04:00
|
|
|
if (load_module ("%s.dll", "module1") < 0) {
|
2002-10-15 00:34:13 +04:00
|
|
|
printf ("load module1 failed\n");
|
|
|
|
}
|
2002-10-15 00:43:33 +04:00
|
|
|
if (load_module ("%s.dll", "module2") < 0) {
|
2002-10-15 00:34:13 +04:00
|
|
|
printf ("load module2 failed\n");
|
|
|
|
}
|
|
|
|
for (int arg=1; arg < argc; arg++) {
|
2002-10-15 00:43:33 +04:00
|
|
|
if (load_module ("%s.dll", argv[arg]) < 0) {
|
2002-10-15 00:34:13 +04:00
|
|
|
printf ("load %s failed\n", argv[arg]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("stop\n");
|
2002-10-16 08:07:58 +04:00
|
|
|
exit(77);
|
2002-10-15 00:34:13 +04:00
|
|
|
}
|