ExternalLibraryFunction.st
changeset 14103 3df000b77712
parent 14037 38519c7f45fa
child 14356 d0e1264c11fe
equal deleted inserted replaced
14102:93c008b8e304 14103:3df000b77712
    14 ExternalFunction subclass:#ExternalLibraryFunction
    14 ExternalFunction subclass:#ExternalLibraryFunction
    15 	instanceVariableNames:'flags moduleName returnType argumentTypes owningClass'
    15 	instanceVariableNames:'flags moduleName returnType argumentTypes owningClass'
    16 	classVariableNames:'DLLPATH FLAG_VIRTUAL FLAG_NONVIRTUAL FLAG_ASYNC
    16 	classVariableNames:'DLLPATH FLAG_VIRTUAL FLAG_NONVIRTUAL FLAG_ASYNC
    17 		FLAG_UNLIMITEDSTACK FLAG_RETVAL_IS_CONST CALLTYPE_MASK
    17 		FLAG_UNLIMITEDSTACK FLAG_RETVAL_IS_CONST CALLTYPE_MASK
    18 		CALLTYPE_API CALLTYPE_C CALLTYPE_OLE CALLTYPE_V8 CALLTYPE_V9
    18 		CALLTYPE_API CALLTYPE_C CALLTYPE_OLE CALLTYPE_V8 CALLTYPE_V9
    19 		CALLTYPE_UNIX64'
    19 		CALLTYPE_UNIX64 DllMapping'
    20 	poolDictionaries:''
    20 	poolDictionaries:''
    21 	category:'System-Support'
    21 	category:'System-Support'
    22 !
    22 !
    23 
    23 
    24 !ExternalLibraryFunction primitiveDefinitions!
    24 !ExternalLibraryFunction primitiveDefinitions!
   182     (oldPath includes:aDirectoryPathName) ifFalse:[
   182     (oldPath includes:aDirectoryPathName) ifFalse:[
   183 	self dllPath:(oldPath asOrderedCollection copyWith:aDirectoryPathName)
   183 	self dllPath:(oldPath asOrderedCollection copyWith:aDirectoryPathName)
   184     ]
   184     ]
   185 !
   185 !
   186 
   186 
       
   187 dllMapping
       
   188     "allows for dll's to be replaced,
       
   189      for example, if you want to use the mozilla sqlite dll
       
   190         C:\Program Files\Mozilla Firefox\mozsqlite3.dll
       
   191      for the sqlite3, execute:
       
   192         ExternalLibraryFunction 
       
   193             dllMapping at:'sqlite3'
       
   194             put: 'C:\Program Files\Mozilla Firefox\mozsqlite3.dll'
       
   195     "
       
   196 
       
   197     DllMapping isNil ifTrue:[
       
   198         DllMapping := Dictionary new.
       
   199     ].
       
   200     ^ DllMapping
       
   201 
       
   202     "Created: / 10-04-2012 / 12:21:45 / cg"
       
   203 !
       
   204 
   187 dllPath
   205 dllPath
   188     ^ DLLPATH
   206     ^ DLLPATH
   189 !
   207 !
   190 
   208 
   191 dllPath:aCollectionOfDirectoryPathNames
   209 dllPath:aCollectionOfDirectoryPathNames
   598         moduleNameUsed := owningClass theNonMetaclass libraryName asSymbol.
   616         moduleNameUsed := owningClass theNonMetaclass libraryName asSymbol.
   599     ].
   617     ].
   600     moduleHandle isNil ifTrue:[
   618     moduleHandle isNil ifTrue:[
   601         handle := self loadLibrary:moduleNameUsed.
   619         handle := self loadLibrary:moduleNameUsed.
   602         handle isNil ifTrue:[
   620         handle isNil ifTrue:[
   603             self error:('Cannot load module: "%1"' bindWith: moduleNameUsed).
   621             self error:('Cannot load dll/module: "%1"' bindWith: moduleNameUsed).
   604         ].
   622         ].
   605         moduleHandle := handle.
   623         moduleHandle := handle.
   606     ].
   624     ].
   607     name isNumber ifFalse:[
   625     name isNumber ifFalse:[
   608         functionName := name.
   626         functionName := name.
   614                 self error:'Missing function: ', name, ' in module: ', moduleNameUsed.
   632                 self error:'Missing function: ', name, ' in module: ', moduleNameUsed.
   615             ].
   633             ].
   616         ].
   634         ].
   617     ].
   635     ].
   618 
   636 
   619     "Modified: / 01-08-2006 / 16:24:14 / cg"
   637     "Modified: / 10-04-2012 / 12:12:44 / cg"
   620     "Modified (comment): / 07-10-2011 / 16:43:11 / cg"
       
   621 !
   638 !
   622 
   639 
   623 loadLibrary:dllName
   640 loadLibrary:dllName
   624     |handle nameString filename|
   641     |handle nameString filename|
   625 
   642 
   626     filename := dllName asFilename.
   643     filename := dllName.
       
   644     DllMapping notNil ifTrue:[
       
   645         filename := DllMapping at:filename ifAbsent:[ filename ]
       
   646     ].
       
   647 
       
   648     filename := filename asFilename.
   627     nameString := filename name.
   649     nameString := filename name.
   628 
   650 
   629     "try to load, maybe the system knows where to find the dll"
   651     "try to load, maybe the system knows where to find the dll"
   630     handle := ObjectFileLoader loadDynamicObject:filename.
   652     handle := ObjectFileLoader loadDynamicObject:filename.
   631     handle notNil ifTrue:[^ handle ].
   653     handle notNil ifTrue:[^ handle ].
   651         "/ try again with the OS-specific dll-extension
   673         "/ try again with the OS-specific dll-extension
   652         ^ self loadLibrary:(filename withSuffix:ObjectFileLoader sharedLibrarySuffix)
   674         ^ self loadLibrary:(filename withSuffix:ObjectFileLoader sharedLibrarySuffix)
   653     ].
   675     ].
   654 
   676 
   655     ^ nil
   677     ^ nil
       
   678 
       
   679     "Modified: / 10-04-2012 / 12:21:06 / cg"
   656 !
   680 !
   657 
   681 
   658 prepareInvoke
   682 prepareInvoke
   659     (moduleHandle isNil or:[self hasCode not]) ifTrue:[
   683     (moduleHandle isNil or:[self hasCode not]) ifTrue:[
   660 	self linkToModule.
   684 	self linkToModule.
  1602 ! !
  1626 ! !
  1603 
  1627 
  1604 !ExternalLibraryFunction class methodsFor:'documentation'!
  1628 !ExternalLibraryFunction class methodsFor:'documentation'!
  1605 
  1629 
  1606 version_CVS
  1630 version_CVS
  1607     ^ '$Header: /cvs/stx/stx/libbasic/ExternalLibraryFunction.st,v 1.85 2012-03-01 15:22:21 mb Exp $'
  1631     ^ '$Header: /cvs/stx/stx/libbasic/ExternalLibraryFunction.st,v 1.86 2012-04-15 16:58:21 cg Exp $'
  1608 !
  1632 !
  1609 
  1633 
  1610 version_SVN
  1634 version_SVN
  1611     ^ '§ Id: ExternalLibraryFunction.st 10643 2011-06-08 21:53:07Z vranyj1  §'
  1635     ^ '§ Id: ExternalLibraryFunction.st 10643 2011-06-08 21:53:07Z vranyj1  §'
  1612 ! !
  1636 ! !