1. Extended dynamic linking routines

Forked from Re: Euphoria SDL2 Wrapper Error

I've been having issues lately when trying to wrap certain libraries: mostly human error in transposing function names, using the proper C types. So I started throwing together some extended dynamic linking routines. These are wrappers around the standard open_dll, define_c_func, c_func, etc. but they provide better debugging and some additional features. I will be updating as I go and any feedback/input is welcome.

Features

  • Additional POSIX C types
  • Automatic CDECL handling
  • Automatic C string/wstring handling
  • Crash on error (can be disabled)
  • Extended debugging and error reporting

Example

with define DLL_DEBUG -- show debug information 
include adv/dll.e 
include adv/machine.e 
 
-- set use_cdecl = 1 and all functions will automatically include the '+' when necessary 
atom libarchive = open_dll( {"libarchive.dll","libarchive.so"}, 1 ) -- use_cdecl = 1 
 
constant 
    _archive_version_number = define_c_func( libarchive, "archive_version_number", {}, C_INT ), 
    _archive_version_string = define_c_func( libarchive, "archive_version_string", {}, C_STRING ), -- notice C_STRING type 
$ 
 
public function archive_version_number() 
    return c_func( _archive_version_number, {} ) 
end function 
 
public function archive_version_string() 
    return c_func( _archive_version_string, {} ) 
end function 
 
-- automatically returns a string from the C function 
printf( 1, "archive_version_string = '%s'\n", {archive_version_string()} ) 

Output

open_dll: libarchive.dll = #69A80000 (using cdecl) 
define_c_func: archive_version_number = 39 
define_c_func: archive_version_string = 40 
archive_version_string = 'libarchive 3.1.2' 

Download

euadvlib.zip (24.6 KB)

-Greg

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu