| 1. |
How Can I Use A Library Written In C From Euphoria? |
|
Answer» You can access shared libraries from a Euphoria program. You can use code from a shared library uing open_dll(libname). This returns an atom which you'll have to REUSE to access individual VARIABLES or functions. You can access a function in a previously opened shared library by calling define_c_function(entry_point,func_name,type_arglist,return_type). This return an id that you can use with call_func(). define_c_proc() and define_c_var() work in the same way, but require less arguments for obvious reasons. You can define a function as a procedure if you'll never care about the returned value. You can access executable machine code using the above. Use "" as an entry point, and the address as name. You can call(address) so that code at address gets executed. The code must be a routine that returns using the near ret instructions (opcode #C3). All used registers must be restored upon return. You'll have to set up the memory area which you'll call() into by coding some machine code into a sequence, allocate() a memory block of the right size and poke()ing the sequence first. You must be AWARE that the code will run in 32 bit protected mode at privilege 3, and that call() requires two task switches, PENALIZING PERFORMANCE unless the asm code has a lot of work to perform. (1) You can access shared libraries from a Euphoria program. You can use code from a shared library uing open_dll(libname). This returns an atom which you'll have to reuse to access individual variables or functions. You can access a function in a previously opened shared library by calling define_c_function(entry_point,func_name,type_arglist,return_type). This return an id that you can use with call_func(). define_c_proc() and define_c_var() work in the same way, but require less arguments for obvious reasons. You can define a function as a procedure if you'll never care about the returned value. You can access executable machine code using the above. Use "" as an entry point, and the address as name. You can call(address) so that code at address gets executed. The code must be a routine that returns using the near ret instructions (opcode #C3). All used registers must be restored upon return. You'll have to set up the memory area which you'll call() into by coding some machine code into a sequence, allocate() a memory block of the right size and poke()ing the sequence first. You must be aware that the code will run in 32 bit protected mode at privilege 3, and that call() requires two task switches, penalizing performance unless the asm code has a lot of work to perform. (1) |
|