summaryrefslogtreecommitdiff
path: root/src/VBox/GuestHost/OpenGL/util/dll.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/VBox/GuestHost/OpenGL/util/dll.c')
-rw-r--r--src/VBox/GuestHost/OpenGL/util/dll.c74
1 files changed, 70 insertions, 4 deletions
diff --git a/src/VBox/GuestHost/OpenGL/util/dll.c b/src/VBox/GuestHost/OpenGL/util/dll.c
index a3245a36..dbc61759 100644
--- a/src/VBox/GuestHost/OpenGL/util/dll.c
+++ b/src/VBox/GuestHost/OpenGL/util/dll.c
@@ -18,6 +18,10 @@
#include <dlfcn.h>
#endif
+#ifdef WINDOWS
+#include <Shlwapi.h>
+#endif
+
#ifdef DARWIN
#include <Carbon/Carbon.h>
@@ -147,7 +151,6 @@ int get_dll_type( const char *name ) {
#endif
-
/*
* Open the named shared library.
* If resolveGlobal is non-zero, unresolved symbols can be satisfied by
@@ -162,14 +165,77 @@ CRDLL *crDLLOpen( const char *dllname, int resolveGlobal )
{
CRDLL *dll;
char *dll_err;
+#if defined(WINDOWS)
+ WCHAR szwPath[MAX_PATH];
+ UINT cwcPath = 0;
+
+ (void) resolveGlobal;
+
+# ifndef CR_NO_GL_SYSTEM_PATH
+ if (PathIsRelative(dllname))
+ {
+ size_t cName = strlen(dllname) + 1;
+# ifdef IN_GUEST
+ cwcPath = GetSystemDirectoryW(szwPath, RT_ELEMENTS(szwPath));
+ if (!cwcPath || cwcPath >= MAX_PATH)
+ {
+ DWORD winEr = GetLastError();
+ crError("GetSystemDirectoryW failed err %d", winEr);
+ SetLastError(winEr);
+ return NULL;
+ }
+# else
+ WCHAR * pszwSlashFile;
+ cwcPath = GetModuleFileNameW(NULL, szwPath, RT_ELEMENTS(szwPath));
+ if (!cwcPath || cwcPath >= MAX_PATH)
+ {
+ DWORD winEr = GetLastError();
+ crError("GetModuleFileNameW failed err %d", winEr);
+ SetLastError(winEr);
+ return NULL;
+ }
+
+ pszwSlashFile = wcsrchr(szwPath, L'\\');
+ if (!pszwSlashFile)
+ {
+ crError("failed to match file name");
+ SetLastError(ERROR_PATH_NOT_FOUND);
+ return NULL;
+ }
+
+ cwcPath = pszwSlashFile - szwPath;
+# endif
+
+ if (cwcPath + 1 + cName > MAX_PATH)
+ {
+ crError("invalid path specified");
+ SetLastError(ERROR_FILENAME_EXCED_RANGE);
+ return NULL;
+ }
+ szwPath[cwcPath] = '\\';
+ ++cwcPath;
+ }
+
+ if (!MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, dllname, -1, &szwPath[cwcPath], MAX_PATH - cwcPath))
+ {
+ DWORD winEr = GetLastError();
+ crError("MultiByteToWideChar failed err %d", winEr);
+ SetLastError(winEr);
+ return NULL;
+ }
+# endif // CR_NO_GL_SYSTEM_PATH
+#endif
dll = (CRDLL *) crAlloc( sizeof( CRDLL ) );
dll->name = crStrdup( dllname );
#if defined(WINDOWS)
- (void) resolveGlobal;
- dll->hinstLib = LoadLibrary( dllname );
- dll_err = NULL;
+ dll->hinstLib = LoadLibraryW( szwPath );
+ if (!dll->hinstLib)
+ {
+ crError("failed to load dll %s", dllname);
+ }
+ dll_err = NULL;
#elif defined(DARWIN)
/* XXX \todo Get better error handling in here */
dll->type = get_dll_type( dllname );