#FEATURE by cg
class: ExternalLibraryFunction
added:
#flushModuleHandlesForLibrary:
#flushModuleHandlesForWhich:
comment/format in: #isCallTypeOLE
changed:
#flushModuleHandlesFor:
#inspectorExtraAttributes
#linkToModule
#loadLibrary:
--- a/ExternalLibraryFunction.st Sat Nov 12 11:50:23 2016 +0100
+++ b/ExternalLibraryFunction.st Sat Nov 12 11:50:41 2016 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 2004 by eXept Software AG
All Rights Reserved
@@ -202,7 +204,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
@@ -324,6 +326,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"
@@ -675,9 +701,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
@@ -891,12 +918,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:[
@@ -910,7 +940,7 @@
].
].
- "Modified: / 26-08-2016 / 17:43:34 / cg"
+ "Modified: / 12-11-2016 / 11:40:03 / cg"
!
loadLibrary:dllName
@@ -921,8 +951,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.
@@ -964,7 +994,7 @@
mayProceed:true.
^ nil
- "Modified: / 10-04-2012 / 12:21:06 / cg"
+ "Modified: / 12-11-2016 / 11:27:23 / cg"
!
prepareInvoke