Call a function in a shared library: Difference between revisions

smalltalk
(added c#)
(smalltalk)
Line 89:
 
# Rest of program</lang>
 
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}
 
The code tries to load the <tt>fakeimglib</tt> (cfr [[Call function in shared library#C|C example]]); if it succeed, the symbol <tt>openimage</tt> will exist, and will be called; otherwise, it is executed an "internal" code for <tt>openimage</tt>. In this example return code of the function of the library is ignored (<tt>ValueHolder null</tt>)
 
<lang smalltalk>DLD addLibrary: 'fakeimglib'.
 
Object subclass: ExtLib [
ExtLib class >> openimage: aString [
(CFunctionDescriptor isFunction: 'openimage')
ifTrue: [
(CFunctionDescriptor for: 'openimage'
returning: #int
withArgs: #( #string ) ) callInto: (ValueHolder null).
] ifFalse: [ ('internal open image %1' % { aString }) displayNl ]
]
].
 
ExtLib openimage: 'prova'.</lang>