1. Ver. 40 Serious Error/Bug
- Posted by bernie Oct 04, 2008
- 952 views
There is a serious Bug in the code. I'am using WIN98 SVN rev. 1191 and do not know if same problem happens in other operating systems. If You run the following simple program you should be able to duplicate the failure of call_back(). -- ================== begin JUNK.EXW ======================= -- This is the simplest example that I can give from my code. include std/dll.e integer i1 = define_c_func(open_dll("user32.dll"),"MessageBeep", {#2000004}, #1000004) ? c_func(i1,{#40}) -- call the function with MB_ICONASTERISK parameter. -- This should print a callback address and it did work in the past. -- Note it is using the same routine_id value that was used in the above -- call which will work. -- -- This does not work but returns a bad routine id error ! ? call_back(i1) if getc(0) then end if -- pause() -- ================== end JUNK.EXW =======================
2. Re: Ver. 40 Serious Error/Bug
- Posted by mattlewis (admin) Oct 04, 2008
- 937 views
There is a serious Bug in the code. I'am using WIN98 SVN rev. 1191 and do not know if same problem happens in other operating systems. If You run the following simple program you should be able to duplicate the failure of call_back().
include std/dll.e integer i1 = define_c_func(open_dll("user32.dll"),"MessageBeep", {#2000004}, #1000004) ? c_func(i1,{#40}) -- call the function with MB_ICONASTERISK parameter. ? call_back(i1) if getc(0) then end if -- pause()
This code is incorrect. Call back is supposed to take a routine id of a euphoria routine, which is not what i1 is. The docs have been somewhat ambiguous in the past, stating that define_c_* returns a routine id. The id they pass only works with c_proc/func. It does not work with call_procedure/function or call_back.
If you got a valid call back in the past, it was only because you passed something that had already been defined as a routine id, and you got a call back for that.
Matt
3. Re: Ver. 40 Serious Error/Bug
- Posted by jimcbrown (admin) Oct 04, 2008
- 925 views
The correct way to get a function pointer/memory address for a C routine is this code:
include std/dll.e integer i1 = define_c_func(open_dll("user32.dll"),"MessageBeep", {#2000004}, #1000004) atom i1_callback = define_c_var(open_dll("user32.dll"),"MessageBeep") ? c_func(i1,{#40}) -- call the function with MB_ICONASTERISK parameter. ? i1_callback if getc(0) then end if -- pause()
define_c_var() works on functions, returning a function pointer (the same thing as call_back() returns), as well as its normal use to return a pointer to a C variable.
There is a serious Bug in the code. I'am using WIN98 SVN rev. 1191 and do not know if same problem happens in other operating systems. If You run the following simple program you should be able to duplicate the failure of call_back().
include std/dll.e integer i1 = define_c_func(open_dll("user32.dll"),"MessageBeep", {#2000004}, #1000004) ? c_func(i1,{#40}) -- call the function with MB_ICONASTERISK parameter. ? call_back(i1) if getc(0) then end if -- pause()
This code is incorrect. Call back is supposed to take a routine id of a euphoria routine, which is not what i1 is. The docs have been somewhat ambiguous in the past, stating that define_c_* returns a routine id. The id they pass only works with c_proc/func. It does not work with call_procedure/function or call_back.
If you got a valid call back in the past, it was only because you passed something that had already been defined as a routine id, and you got a call back for that.
Matt
4. Re: Ver. 40 Serious Error/Bug
- Posted by bernie Oct 04, 2008
- 923 views
This code is incorrect. Call back is supposed to take a routine id of a euphoria routine, which is not what i1 is. The docs have been somewhat ambiguous in the past, stating that define_c_* returns a routine id. The id they pass only works with c_proc/func. It does not work with call_procedure/function or call_back.
If you got a valid call back in the past, it was only because you passed something that had already been defined as a routine id, and you got a call back for that.
Matt
Thanks Matt:
My big mistake was reading and beleaving the library doc.
5. Re: Ver. 40 Serious Error/Bug
- Posted by bernie Oct 04, 2008
- 916 views
The correct way to get a function pointer/memory address for a C routine is this code:
include std/dll.e integer i1 = define_c_func(open_dll("user32.dll"),"MessageBeep", {#2000004}, #1000004) atom i1_callback = define_c_var(open_dll("user32.dll"),"MessageBeep") ? c_func(i1,{#40}) -- call the function with MB_ICONASTERISK parameter. ? i1_callback if getc(0) then end if -- pause()
define_c_var() works on functions, returning a function pointer (the same thing as call_back() returns), as well as its normal use to return a pointer to a C variable.
Thanks Jim:
I knew about that but I got hung up on beleaving what the library doc said.
6. Re: Ver. 40 Serious Error/Bug
- Posted by jimcbrown (admin) Oct 04, 2008
- 921 views
Thanks Jim:
I knew about that but I got hung up on beleaving what the library doc said.
Agreed, the c_func/c_proc "routine" ids should probably be called something else. Perhaps C-func ids?