]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/alien/libraries/finder/windows/windows.factor
alien.c-types: not necessary to import `short` differently anymore
[factor.git] / basis / alien / libraries / finder / windows / windows.factor
index 3ea834930d7335cbf7c89cc636a27b4c6765caa1..8272bd7737abd9d9883cf33733d12230280451a6 100644 (file)
@@ -1,10 +1,12 @@
 ! Copyright (C) 2013 Björn Lindqvist, John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: alien.libraries.finder arrays combinators.short-circuit
-environment io.backend io.files io.files.info io.pathnames kernel
-sequences splitting system system-info.windows ;
-
+USING: alien.c-types alien.data alien.libraries.finder
+alien.strings arrays combinators.short-circuit environment
+io.backend io.files io.files.info io.pathnames kernel sequences
+specialized-arrays splitting system system-info.windows
+windows.kernel32 ;
+SPECIALIZED-ARRAY: ushort
 IN: alien.libraries.finder.windows
 
 <PRIVATE
@@ -26,9 +28,20 @@ IN: alien.libraries.finder.windows
         ] with map concat
     ] if ;
 
+: find-library-paths ( name -- path/f )
+    candidate-paths [
+        { [ file-exists? ] [ file-info regular-file? ] } 1&&
+    ] find nip ;
+
+: find-library-file ( name -- path/f )
+    f DONT_RESOLVE_DLL_REFERENCES LoadLibraryEx [
+        [
+            32768 ushort (c-array) [ 32768 GetModuleFileName drop ] keep
+            alien>native-string
+        ] [ FreeLibrary drop ] bi
+    ] [ f ] if* ;
+
 PRIVATE>
 
 M: windows find-library*
-    candidate-paths [
-        { [ exists? ] [ file-info regular-file? ] } 1&&
-    ] find nip ;
+    { [ find-library-paths ] [ find-library-file ] } 1|| ;