summaryrefslogtreecommitdiff
path: root/src/VBox/GuestHost/OpenGL/util/dll.c
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2014-03-26 19:21:20 +0000
committer <>2014-05-08 15:03:54 +0000
commitfb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch)
treec2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/GuestHost/OpenGL/util/dll.c
parent58ed4748338f9466599adfc8a9171280ed99e23f (diff)
downloadVirtualBox-master.tar.gz
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
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 );