RE: DLL Automatic Wrapper Generator
- Posted by bensler at mail.com Mar 01, 2002
- 462 views
I've updated DAWG to handle object arguments for string parameters. I also fixed a couple little bugs I discovered when I did a detailed test. This is what you can do with DAWG: <TEST.EXW> include dawg.e constant DLL_List={ {"some.dll", { {"Some_Proc",{{},C_INT,C_ULONG}}, {"Some_Func",{{},{},{},{}},C_CHAR}, {"Another_Func",{C_SHORT,C_LONG},{}}, {"Variable"} } } } build_wrapper("test_wrap.e",DLL_List,1) puts(2,"done") <END TEST.EXW> This is what is generated: <TEST_WRAP.E> -- wrapper file generated using dawg.e by Chris Bensler -- link to the DLL's global constant some_dll = link_dll("some.dll") -- link to the c_var's global constant Variable_var = link_c_var(some_dll, "Variable") -- link to the c_func's global constant xSome_Func = link_c_func(some_dll, "Some_Func", {C_POINTER,C_POINTER,C_POINTER,C_POINTER}, C_CHAR) global constant xAnother_Func = link_c_func(some_dll, "Another_Func", {C_SHORT,C_LONG}, C_POINTER) -- link to the c_proc's global constant xSome_Proc = link_c_proc(some_dll, "Some_Proc", {C_POINTER,C_LONG,C_POINTER}) ----------------------------- -- c_func wrappers -- global function Some_Func(object arg1,object arg2,object arg3,object arg4) atom ret atom tmp1,tmp2,tmp3,tmp4 if sequence(arg1) then tmp1 = allocate_string(arg1) else tmp1 = arg1 end if if sequence(arg2) then tmp2 = allocate_string(arg2) else tmp2 = arg2 end if if sequence(arg3) then tmp3 = allocate_string(arg3) else tmp3 = arg3 end if if sequence(arg4) then tmp4 = allocate_string(arg4) else tmp4 = arg4 end if ret = c_func(xSome_Func,{tmp1,tmp2,tmp3,tmp4}) free(tmp1) free(tmp2) free(tmp3) free(tmp4) return ret end function global function Another_Func(integer arg1,integer arg2) return peek_string(c_func(xAnother_Func,{arg1,arg2})) end function ----------------------------- -- c_proc wrappers -- global procedure Some_Proc(object arg1,integer arg2,atom arg3) atom tmp1 if sequence(arg1) then tmp1 = allocate_string(arg1) else tmp1 = arg1 end if c_proc(xSome_Proc,{tmp1,arg2,arg3}) free(tmp1) end procedure <END TEST_WRAP.E> Chris bensler at mail.com wrote: > It does already handle passing strings, and does the work for them, even > > for the retVal of a c_func, but not objects yet. > This version is still a rough prototype. I will probably allow for more > flexibility. > > Any sequence used as an arg variable or retVal will be treated as such > in the wrapper. > > if you define: > {"Function",{C_INT,{},C_INT,etc},{}} > > the wrapper would look like this: (I haven't tested this yet) > global function Function(integer arg1, sequence arg2, integer arg3, etc) > atom ret > atom tmp2 > allocate_string(arg2) > ret = c_func(xFunction,{arg1,tmp2,arg3,etc}) > free(tmp2) > return peek_string(ret) > end function > > If all the args are sequences, it would allocate for all of them. > > It shouldn't be hard to fix it to work for pointers or atoms. > > > Chris > > > Andy Serpa wrote: > > > > > Let me know what you think. I would like to get some test results > > > before I give it to the archives. > > > > > > > Looks good. One thing I would like to see is the ability to define a > > string argument in c function, and be able to pass to the generated > > wrapper function a Euphoria sequence/string. The function would > > automatically allocate_string(), call the c_func, then free() it. And > > if I pass an atom to the function instead, then it will assume it is a > > pointer and skip that step... > > > >