ExternalLibraryFunction.st
changeset 13782 1994fe87f21e
parent 13412 9a5f99d66cd9
child 14037 38519c7f45fa
equal deleted inserted replaced
13781:c691e88e1900 13782:1994fe87f21e
   537      I.e. retrieve the module handle and the code pointer."
   537      I.e. retrieve the module handle and the code pointer."
   538 
   538 
   539     |handle moduleNameUsed functionName|
   539     |handle moduleNameUsed functionName|
   540 
   540 
   541     name isNumber ifTrue:[
   541     name isNumber ifTrue:[
   542 	self isCPPFunction ifTrue:[
   542         self isCPPFunction ifTrue:[
   543 	    "/ no need to load a dll.
   543             "/ no need to load a dll.
   544 	    ^ self
   544             ^ self
   545 	]
   545         ]
   546     ].
   546     ].
   547 
   547 
       
   548     "/ in some other smalltalks, there is no moduleName in the ffi-spec;
       
   549     "/ instead, the class provides the libraryName...
   548     (moduleNameUsed := moduleName) isNil ifTrue:[
   550     (moduleNameUsed := moduleName) isNil ifTrue:[
   549 	owningClass isNil ifTrue:[
   551         owningClass isNil ifTrue:[
   550 	    self error:'Missing moduleName'.
   552             self error:'Missing moduleName'.
   551 	].
   553         ].
   552 	moduleNameUsed := owningClass theNonMetaclass libraryName asSymbol.
   554         moduleNameUsed := owningClass theNonMetaclass libraryName asSymbol.
   553     ].
   555     ].
   554     moduleHandle isNil ifTrue:[
   556     moduleHandle isNil ifTrue:[
   555 	handle := self loadLibrary:moduleNameUsed.
   557         handle := self loadLibrary:moduleNameUsed.
   556 	handle isNil ifTrue:[
   558         handle isNil ifTrue:[
   557 	    self error:('Cannot load module: "%1"' bindWith: moduleNameUsed).
   559             self error:('Cannot load module: "%1"' bindWith: moduleNameUsed).
   558 	].
   560         ].
   559 	moduleHandle := handle.
   561         moduleHandle := handle.
   560     ].
   562     ].
   561     name isNumber ifFalse:[
   563     name isNumber ifFalse:[
   562 	functionName := name.
   564         functionName := name.
   563 	(moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[
   565         (moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[
   564 	    functionName := ('_', functionName) asSymbol.
   566             functionName := ('_', functionName) asSymbol.
   565 
   567 
   566 	    (moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[
   568             (moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[
   567 		moduleHandle := nil.
   569                 moduleHandle := nil.
   568 		self error:'Missing function: ', name, ' in module: ', moduleNameUsed.
   570                 self error:'Missing function: ', name, ' in module: ', moduleNameUsed.
   569 	    ].
   571             ].
   570 	].
   572         ].
   571     ].
   573     ].
   572 
   574 
   573     "Modified: / 01-08-2006 / 16:24:14 / cg"
   575     "Modified: / 01-08-2006 / 16:24:14 / cg"
       
   576     "Modified (comment): / 07-10-2011 / 16:43:11 / cg"
   574 !
   577 !
   575 
   578 
   576 loadLibrary:dllName
   579 loadLibrary:dllName
   577     |handle nameString filename|
   580     |handle nameString filename|
   578 
   581 
  1498 ! !
  1501 ! !
  1499 
  1502 
  1500 !ExternalLibraryFunction class methodsFor:'documentation'!
  1503 !ExternalLibraryFunction class methodsFor:'documentation'!
  1501 
  1504 
  1502 version_CVS
  1505 version_CVS
  1503     ^ '$Header: /cvs/stx/stx/libbasic/ExternalLibraryFunction.st,v 1.83 2011-06-28 12:07:39 vrany Exp $'
  1506     ^ '$Header: /cvs/stx/stx/libbasic/ExternalLibraryFunction.st,v 1.84 2011-10-07 18:01:43 cg Exp $'
  1504 !
  1507 !
  1505 
  1508 
  1506 version_SVN
  1509 version_SVN
  1507     ^ ' Id: ExternalLibraryFunction.st 10643 2011-06-08 21:53:07Z vranyj1  '
  1510     ^ '§ Id: ExternalLibraryFunction.st 10643 2011-06-08 21:53:07Z vranyj1  §'
  1508 ! !
  1511 ! !
  1509 
  1512 
  1510 ExternalLibraryFunction initialize!
  1513 ExternalLibraryFunction initialize!