Fixes to both versions of win_dynld.c.

This commit is contained in:
OBattler
2022-11-02 06:28:27 +01:00
parent e2391ca6ef
commit 4fb3228628
2 changed files with 32 additions and 22 deletions

View File

@@ -23,6 +23,7 @@
#include <windows.h> #include <windows.h>
#define HAVE_STDARG_H #define HAVE_STDARG_H
#include <86box/86box.h> #include <86box/86box.h>
#include <86box/plat.h>
#include <86box/plat_dynld.h> #include <86box/plat_dynld.h>
@@ -52,9 +53,11 @@ dynld_module(const char *name, dllimp_t *table)
HMODULE h; HMODULE h;
dllimp_t *imp; dllimp_t *imp;
void *func; void *func;
WCHAR uname[512];
/* See if we can load the desired module. */ /* See if we can load the desired module. */
if ((h = LoadLibrary(name)) == NULL) { mbstoc16s(uname, name, strlen(name) + 1);
if ((h = LoadLibrary(uname)) == NULL) {
dynld_log("DynLd(\"%s\"): library not found! (%08X)\n", name, GetLastError()); dynld_log("DynLd(\"%s\"): library not found! (%08X)\n", name, GetLastError());
return(NULL); return(NULL);
} }

View File

@@ -23,61 +23,68 @@
#include <windows.h> #include <windows.h>
#define HAVE_STDARG_H #define HAVE_STDARG_H
#include <86box/86box.h> #include <86box/86box.h>
#include <86box/plat.h>
#include <86box/plat_dynld.h> #include <86box/plat_dynld.h>
#ifdef ENABLE_DYNLD_LOG #ifdef ENABLE_DYNLD_LOG
int dynld_do_log = ENABLE_DYNLD_LOG; int dynld_do_log = ENABLE_DYNLD_LOG;
static void static void
dynld_log(const char *fmt, ...) dynld_log(const char *fmt, ...)
{ {
va_list ap; va_list ap;
if (dynld_do_log) { if (dynld_do_log) {
va_start(ap, fmt); va_start(ap, fmt);
pclog_ex(fmt, ap); pclog_ex(fmt, ap);
va_end(ap); va_end(ap);
} }
} }
#else #else
# define dynld_log(fmt, ...) #define dynld_log(fmt, ...)
#endif #endif
void * void *
dynld_module(const char *name, dllimp_t *table) dynld_module(const char *name, dllimp_t *table)
{ {
HMODULE h; HMODULE h;
dllimp_t *imp; dllimp_t *imp;
void *func; void *func;
WCHAR uname[512];
/* See if we can load the desired module. */ /* See if we can load the desired module. */
if ((h = LoadLibrary(name)) == NULL) { mbstoc16s(uname, name, strlen(name) + 1);
dynld_log("DynLd(\"%s\"): library not found! (%08X)\n", name, GetLastError()); if ((h = LoadLibrary(uname)) == NULL) {
return (NULL); dynld_log("DynLd(\"%s\"): library not found! (%08X)\n", name, GetLastError());
return(NULL);
} }
/* Now load the desired function pointers. */ /* Now load the desired function pointers. */
for (imp = table; imp->name != NULL; imp++) { for (imp=table; imp->name!=NULL; imp++) {
func = GetProcAddress(h, imp->name); func = GetProcAddress(h, imp->name);
if (func == NULL) { if (func == NULL) {
dynld_log("DynLd(\"%s\"): function '%s' not found! (%08X)\n", dynld_log("DynLd(\"%s\"): function '%s' not found! (%08X)\n",
name, imp->name, GetLastError()); name, imp->name, GetLastError());
FreeLibrary(h); FreeLibrary(h);
return (NULL); return(NULL);
} }
/* To overcome typing issues.. */ /* To overcome typing issues.. */
*(char **) imp->func = (char *) func; *(char **)imp->func = (char *)func;
} }
/* All good. */ /* All good. */
dynld_log("loaded %s\n", name); dynld_log("loaded %s\n", name);
return ((void *) h); return((void *)h);
} }
void void
dynld_close(void *handle) dynld_close(void *handle)
{ {
if (handle != NULL) if (handle != NULL)
FreeLibrary((HMODULE) handle); FreeLibrary((HMODULE)handle);
} }