OSX dylib
BlitzMax Forums/BlitzMax Beginners Area/OSX dylib
| ||
I have a dylib dynamic library with a .h file (see below). #include <CoreFoundation/CoreFoundation.h> typedef struct DriverHandler* OPNInterface; extern "C" OPNInterface CreateOPNInterface(); ... How can I call the CreateOPNInterface() from BlitzMax ? Import ? Extern ? |
| ||
Waouh... Nothing more easy than that ? trict Framework brl.blitz Extern "C" ' see /usr/include/dlfcn.h, POSIX part only Function dlclose:Byte Ptr (Handle:Byte Ptr) Function dlerror$z() Function dlopen:Byte Ptr (Path$z, Mode:Int) Function dlsym:Byte Ptr (Handle:Byte Ptr, Symbol$z) End Extern Const RTLD_LAZY = $01 ' lazy function call binding Const RTLD_NOW = $02 ' immediate function call binding Const RTLD_LOCAL = $04 Const RTLD_GLOBAL = $08 Local Library:Byte Ptr = dlopen("libopn_driver.dylib", RTLD_GLOBAL | RTLD_NOW) If (Not Library) Then WriteStdout "Library could not be loaded~n" Throw "library not found" Else WriteStdout "Library loaded~n" End If WriteStdout "dlerror() = " + dlerror() + "~n" Local CreateOPNInterface: Byte Ptr() CreateOPNInterface = dlsym(Library,"CreateOPNInterface") If (Not CreateOPNInterface) Then WriteStdout "unable to obtain symbol 'CreateOPNInterface'~n" End If Local OPN:Byte Ptr=CreateOPNInterface(); |