Re: how to write a wrapper?
- Posted by johnw <mail at j-webst?r.co?uk> Aug 03, 2007
- 516 views
Jules wrote: > > most of the Euphoria "heavyweights" (as opposed to the "lightweights", like > me) devote much of their time and effort into wrapping libraries to extend > Eu's > functionality. I understand the basic mechanics of this: > > There are actually 3 steps to go through. > > 1/ Your wrapper must open a shared file (.dll on Windows, .so on Linux/BSD) > > using open_dll() (be sure to include machine.e). This function will return > some atom I'll call entry_point. > > 2/ For each routine you need to wrap, define a constant representing that > routine using defie_c_func (or _proc): > > constant > the_func=define_c_func(entry_point,func_name,arg_type_list,return_type) > > You can also access public variables using define_c_var(). > > 3/ Then, in any program using the routines, including your own wrapper, > you use c_func() or c_proc() to call the routine, using the identifiers > defined in stage 2 as routine ids. > > And that should be all, unless you have to fiddle with calling convention. > If the doc for your dll talks about cdecl, then there is a specific syntax > to use in define_c_func. > > (thanks to CChris for this post). I'd like to have a go at writing a simple > wrapper but am unsure where to start. I assume I don't need much knowledge of > C, but surely I need some? and if so, what, particularly? I don't (hopefully) > need spoon-feeding, but if someone could point me in the right direction, that > would be great. I'm sure there are many other Eu coders who would like to see > a tutorial on this subject. I'd be happy to write one myself, once I've > learned > the basics. I am in the same boat, a couple of years ago I bought a Velleman usb interface board and it came with a DLL, I managed to hack a wrapper by looking at code writen by others and used it as a template, I was really pleased when it worked and suprised that I had managed to do it, the DLL was well documented and only had a few functions. if I were good at writing wrappers I could use dll's written by far better programmers than me,(just about everyone) and perhaps give me access to code written for specialised tasks.