changeset 350:655cafde0859

- dynload/windows: dlLoadLibrary behaviour now more in line with other platforms by not trying to load provided path with .dll suffix - cosmetics, cr update
author Tassilo Philipp
date Fri, 10 Jan 2020 13:30:57 +0100
parents fb70995ac923
children 6b37ccbb2f91
files dynload/dynload_windows.c test/dynload_plain/Nmakefile
diffstat 2 files changed, 15 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/dynload/dynload_windows.c	Wed Jan 08 18:20:49 2020 +0100
+++ b/dynload/dynload_windows.c	Fri Jan 10 13:30:57 2020 +0100
@@ -6,7 +6,7 @@
  Description: 
  License:
 
-   Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>, 
+   Copyright (c) 2007-2020 Daniel Adler <dadler@uni-goettingen.de>,
                            Tassilo Philipp <tphilipp@potion-studios.com>
 
    Permission to use, copy, modify, and distribute this software for any
@@ -45,7 +45,7 @@
   if(libPath == NULL)
     return (DLLib*)GetModuleHandle(NULL);
   else {
-    /* convert from UTF-8 to wide chars, so count required size... */
+    /* convert from UTF-8 to wide chars, so count required size */
     DLLib* pLib;
     wchar_t* ws;
     int r = MultiByteToWideChar(CP_UTF8, 0, libPath, -1, NULL, 0);
@@ -53,14 +53,21 @@
       return NULL;
     }
 
-    /* ... reserve temp space, ... */
-    ws = (wchar_t*)dlAllocMem(r * sizeof(wchar_t));
+    /* Reserve temp space with room for extra '.' suffix (see below) */
+    ws = (wchar_t*)dlAllocMem((r+1) * sizeof(wchar_t));
     if(!ws)
       return NULL;
 
-    /* ... convert (and use r as success flag), ... */
-    r = (MultiByteToWideChar(CP_UTF8, 0, libPath, -1, ws, r) == r);
-    pLib = (DLLib*)(r ? LoadLibraryW(ws) : NULL);
+    /* Convert path and add a '.' suffix, needed to tell windows not to add
+       .dll to any path that doesn't have it (see MS doc for LoadLibraryW).
+       This is to get same behaviour as on other platforms which don't  do any
+       magic like this. Library search path behaviour stays unaffected, though */
+    pLib = NULL;
+    if(MultiByteToWideChar(CP_UTF8, 0, libPath, -1, ws, r) == r) {
+        ws[r-1] = '.';
+        ws[r] = 0;
+        pLib = (DLLib*)LoadLibraryW(ws);
+    }
 
     /* ... free temp space and return handle */
     dlFreeMem(ws);
--- a/test/dynload_plain/Nmakefile	Wed Jan 08 18:20:49 2020 +0100
+++ b/test/dynload_plain/Nmakefile	Fri Jan 10 13:30:57 2020 +0100
@@ -1,6 +1,6 @@
 #//////////////////////////////////////////////////////////////////////////////
 #
-# Copyright (c) 2017 Tassilo Philipp <tphilipp@potion-studios.com>
+# Copyright (c) 2017-2020 Tassilo Philipp <tphilipp@potion-studios.com>
 #
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above