only bring in as many sdl things as are strictly necessary
[tangerine.git] / arch / all-mingw32 / bootstrap / hostlib.c
blobdd06e2cb9c180a9be6ba9c6a11c4f8732c59f2cc
1 #include <stdio.h>
2 #include <windows.h>
4 #include "hostlib.h"
6 #define D(x)
8 static void GetErrorStr(char **error, BOOL condition)
10 if (error != NULL) {
11 if (condition) {
12 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
13 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), error, 0, NULL );
14 } else
15 *error = NULL;
19 void Host_HostLib_FreeErrorStr(char *error)
21 LocalFree(error);
24 void *Host_HostLib_Open(const char *filename, char **error)
26 HMODULE handle;
28 D(printf("[hostlib] Open: filename=%s\n", filename));
29 handle = LoadLibrary(filename);
30 GetErrorStr(error, !handle);
32 return handle;
35 int Host_HostLib_Close(void *handle, char **error)
37 int err;
39 D(printf("[hostlib] Close: handle=0x%08x\n", handle));
40 err = !FreeLibrary(handle);
41 GetErrorStr(error, err);
43 return err;
46 void *Host_HostLib_GetPointer(void *handle, const char *symbol, char **error)
48 void *ptr;
50 D(printf("[hostlib] GetPointer: handle=0x%08x, symbol=%s\n", handle, symbol));
51 ptr = GetProcAddress(handle, symbol);
52 GetErrorStr(error, !ptr);
53 return ptr;
56 unsigned long Host_HostLib_GetInterface(void *handle, char **names, void **funcs)
58 unsigned long unresolved = 0;
60 for (; *names; names++) {
61 *funcs = GetProcAddress(handle, *names);
62 D(printf("[hostlib] GetInterface: handle=0x%08x, symbol=%s, value=0x%08x\n", handle, *names, *funcs));
63 if (*funcs++ == NULL)
64 unresolved++;
66 return unresolved;