ExternalLibraryFunction.st
branchjv
changeset 21024 8734987eb5c7
parent 20579 9add81aadb7a
parent 20958 4a8561ed705e
child 21026 81e280fc1b93
--- a/ExternalLibraryFunction.st	Wed Oct 26 23:35:39 2016 +0100
+++ b/ExternalLibraryFunction.st	Fri Nov 18 20:48:04 2016 +0000
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 2004 by eXept Software AG
 	      All Rights Reserved
@@ -227,7 +229,7 @@
   Synchronous vs. Asynchronous calls:
 
     by default, foreign function calls are synchronous, effectively blocking the whole ST/X system
-    (that is by purpose,because most C-code is not prepared for being interrupted, and also, normal
+    (that is by purpose,´because most C-code is not prepared for being interrupted, and also, normal
      code is not prepared for a garbage collector to move objects around, while another C thread might
      access the data...).
     Therefore, the following will block all ST/X activity for 10 seconds
@@ -349,6 +351,30 @@
     DLLPATH := aCollectionOfDirectoryPathNames
 !
 
+flushModuleHandlesForLibrary:aLibraryName
+    self flushModuleHandlesForWhich:[:fn | fn moduleName = aLibraryName].
+
+    "
+     self flushModuleHandlesForLibrary:'ole32.dll'
+    "
+
+    "Created: / 12-11-2016 / 11:49:09 / cg"
+!
+
+flushModuleHandlesForWhich:aBlock
+    self allInstancesDo:[:fn |
+        (aBlock value:fn) ifTrue:[
+            fn setModuleHandle:nil.
+        ]
+    ].
+
+    "
+     self flushModuleHandlesForLibrary:'ole32.dll'
+    "
+
+    "Created: / 12-11-2016 / 11:48:32 / cg"
+!
+
 initialize
     "using inline access to corresponding c--defines to avoid duplicate places of knowledge"
 
@@ -700,9 +726,10 @@
 isCallTypeOLE
     "is this an OLE-object call ? (eg. a virtual c++ call; same as isCallTypeCPP)"
 
-    ^ ((flags ? 0) bitTest: FLAG_VIRTUAL).
+    ^ (flags ? 0) bitTest: FLAG_VIRTUAL.
 
     "Created: / 01-08-2006 / 15:21:23 / cg"
+    "Modified (format): / 12-11-2016 / 11:37:38 / cg"
 !
 
 isConstReturnValue
@@ -918,12 +945,15 @@
         "/ speedup. in 95% of all calls, the same moduleName is resolved here
         (LastModuleHandleHolder isNil
         or:[ (handle := LastModuleHandleHolder at:1) isNil
-        or:[ LastModuleHandleName ~= moduleNameUsed ]]) ifTrue:[
+        or:[ handle == -1
+        or:[ LastModuleHandleName ~= moduleNameUsed ]]]) ifTrue:[
 
             handle := self loadLibrary:moduleNameUsed.
+            handle isNil ifTrue:[ self error:'Failed to load library: ',moduleNameUsed].
             LastModuleHandleHolder := WeakArray with:handle.
             LastModuleHandleName := moduleNameUsed.
         ].
+        self assert:(handle isInteger not).
         moduleHandle := handle.
     ].
     name isNumber ifFalse:[
@@ -937,7 +967,7 @@
         ].
     ].
 
-    "Modified: / 26-08-2016 / 17:43:34 / cg"
+    "Modified: / 12-11-2016 / 11:40:03 / cg"
 !
 
 loadLibrary:dllName
@@ -948,8 +978,8 @@
 
     |handle nameString filename dllPathes|
 
-    (ObjectFileLoader isNil or:[ObjectFileLoader canLoadObjectFiles not]) ifTrue:[
-        self error:('ObjectFileLoader class missing: cannot load dll/module: "%1"' bindWith:nameString).
+    (ObjectFileLoader notNil and:[ObjectFileLoader canLoadObjectFiles]) ifFalse:[
+        self error:('ObjectFileLoader cannot load dll/module: "%1"' bindWith:nameString).
     ].
 
     filename := dllName.
@@ -991,7 +1021,7 @@
         mayProceed:true.
     ^ nil
 
-    "Modified: / 10-04-2012 / 12:21:06 / cg"
+    "Modified: / 12-11-2016 / 11:27:23 / cg"
 !
 
 prepareInvoke