You shouldn't really need to use dlopen() or LoadLibrary(). That is the beauty of LCB. The "binds to" directive does exactly that.
The only time I looked at the C code of a library was to check which type of variables are being passed and returned to each function.
Please find attached some code that I used to bind to libfluidsynth.
FYI I can bind to the dll if it is in the same folder as the lcb script too....AND you can bind to it in a subfolder too if you specify it in the "binds to" directive. I will explain after this.
LCB Code
Code: Select all
library community.livecode.everyone.fluidsynth
metadata title is "Fluid Synth Library"
metadata author is "Author"
metadata version is "1.0.0"
use com.livecode.foreign
foreign handler new_fluid_settings ( ) returns CUint binds to "libfluidsynth>new_fluid_settings"
foreign handler new_fluid_synth ( in tSettings as CUint ) returns CUint binds to "libfluidsynth>new_fluid_synth"
foreign handler new_fluid_audio_driver ( in tSettings as CUint, in tSynth as CUint ) returns CUint binds to "libfluidsynth>new_fluid_audio_driver"
foreign handler fluid_synth_sfload ( in tSynth as CUint, in tFile as ZStringNative, in tPresets as CUint ) returns CUint binds to "libfluidsynth>fluid_synth_sfload"
foreign handler fluid_synth_noteon ( in tSynth as CUint, in tChan as CUint, in tKey as CUint, in tVel as CUint ) returns CUint binds to "libfluidsynth>fluid_synth_noteon"
foreign handler fluid_synth_noteoff ( in tSynth as CUint, in tChan as CUint, in tKey as CUint ) returns CUint binds to "libfluidsynth>fluid_synth_noteoff"
public handler NewFluidSettings ( ) returns Integer
return new_fluid_settings ( )
end handler
public handler NewFluidSynth ( in tSettings as Integer ) returns Integer
return new_fluid_synth ( tSettings )
end handler
public handler NewFluidAudioDriver ( in tSettings as Integer, in tSynth as Integer ) returns Integer
return new_fluid_audio_driver ( tSettings, tSynth )
end handler
public handler FluidSynthSFLoad ( in tSynth as Integer, in tFile as String, in tPresets as Integer ) returns Integer
return fluid_synth_sfload ( tSynth, tFile , tPresets )
end handler
public handler FluidSynthNoteOn ( in tSynth as Integer, in tChan as Integer, in tKey as Integer, in tVel as Integer ) returns Integer
return fluid_synth_noteon ( tSynth, tChan, tKey, tVel )
end handler
public handler FluidSynthNoteOff ( in tSynth as Integer, in tChan as Integer, in tKey as Integer ) returns Integer
return fluid_synth_noteoff ( tSynth, tChan, tKey )
end handler
end library
Code: Select all
global tSettings
global tSynth
global tDriver
global tFont
on test
put NewFluidSettings ( ) into tSettings
put NewFluidSynth ( tSettings ) into tSynth
put NewFluidAudioDriver ( tSettings, tSynth ) into tDriver
put FluidSynthSFLoad ( tSynth, "test.SF2", 1 ) into tFont
repeat with tKey = 1 to 127
FluidSynthNoteOn tSynth, 0, tKey, 80
wait 1 second
FluidSynthNoteOff tSynth, 0, tKey
end repeat
-- cleanup ie delete synths etc.. here
end test
Code: Select all
binds to "libfolder/libfluidsynth>dll_function_goes_here"
So this would tell me that you certainly can specify a relative path for the "binds to" directive. I can only assume you can also specify an absolute path too ( but that is not very desirable anyway "
Now I don't propose that this is in any way the correct way to do things. If you look at the C API of fluid synch you will notice that new_fluid_synth ( ) etc... return pointers to custom types. I have been a bad bad man and converted them to UInts, to get them into my LCS. This is not the way to do things at all but hey it works for the purposes of this.
Note this would only work for 32 bit pointers. In a 64 bit system, the pointers would be too large to cast to a UInt and you would lose bits off the end causing all sorts of nasties.
I am, of course, over simplifying it but I too am a non programmer.
NB to play the sample you will need a file called "test.sf2" beside the dylib or in the system folder.
I hope this works for my OSX brethren, but on Win32 it seems OK