Wrapping C Libraries callback

new topic     » topic index » view thread      » older message » newer message

Hello,

I am wondering how you properly wrap a callback function from C library? When you see something like void(*call back) or something function(void*)? I am sure there is a way to properly wrap these. Usually I've done something like the code below. Though I am sure there is a better way to actually wrap these callback functions.

atom dll = open("dll.dll") 
 
if dll = -1 then 
  puts(1,"Could not load DLL!\n") 
  abort(0) 
end if 
 
--Code here is just for example 
 
constant xmyFunction = define_c_func(dll,"myFunction",{C_POINTER},C_POINTER) --where the pointer is the *callback from the C function 
 
function myFunction(atom x) 
 return c_func(xmyFunction,{x}) 
end function 

Again, I think there is more to then just simply wrapping it like that. I think a couple extra steps are needed when you have a more complex function to wrap. Any is appericated.

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu