1. Euphoria SDL2 Wrapper Error
- Posted by Lone_EverGreen_Ranger Jun 24, 2013
- 1403 views
Hello,
I am getting this error when testing out my wrapper. c_proc/c_func: bad routine number (-1)
SDL2Wrapper Code:
without warning include std/math.e include std/machine.e include std/dll.e atom sdl sdl = open_dll("SDL2.dll") if sdl = -1 then puts(1,"Could not open SDL2.dll!\n") abort(1) end if public constant SDL_INIT_TIMER = 0x00000001 public constant SDL_INIT_AUDIO = 0x00000010 public constant SDL_INIT_VIDEO = 0x00000020 public constant SDL_INIT_JOYSTICK = 0x00000200 public constant SDL_INIT_HAPTIC = 0x00001000 public constant SDL_INIT_GAMECONTROLLER = 0x00002000 public constant SDL_INIT_NOPARACHUTE = 0x00100000 public constant SDL_INIT_EVERYTHING = #0000FFFF public constant xSDL_Init = define_c_func(sdl,"SDL_Init",{C_UINT},C_INT), xSDL_InitSubSystem = define_c_func(sdl,"SDL_InitSubSystem",{C_UINT},C_INT), xSDL_Quit = define_c_proc(sdl,"SDL_Quit",{}), xSDL_QuitSubSystem = define_c_proc(sdl,"SDL_QuitSubsystem",{C_UINT}), xSDL_WasInit = define_c_func(sdl,"SDL_WasInit",{C_UINT},C_UINT) public function SDL_Init(atom flags) return c_func(xSDL_Init,{flags}) end function public function SDL_InitSubSystem(atom flags) return c_func(xSDL_InitSubSystem,{flags}) end function public procedure SDL_QuitSubSystem(atom flags) c_proc(xSDL_QuitSubSystem,{flags}) end procedure public procedure SDL_Quit() c_proc(xSDL_Quit,{}) end procedure public function SDL_WasInit(atom flags) return c_func(xSDL_WasInit,{flags}) end function
include EuSDL2.ew atom dummy,pixels atom format,keystate atom surface,buffer dummy = SDL_Init(SDL_INIT_VIDEO) if dummy = -1 then puts(1,"Could not init SDL!") end if
Any ideas on what might be going on? I can post more code if it is needed.
2. Re: Euphoria SDL2 Wrapper Error
- Posted by jimcbrown (admin) Jun 24, 2013
- 1400 views
Hello,
I am getting this error when testing out my wrapper. c_proc/c_func: bad routine number (-1)
Any ideas on what might be going on? I can post more code if it is needed.
SDL2Wrapper Code:
sdl = open_dll("SDL2.dll") if sdl = -1 then puts(1,"Could not open SDL2.dll!\n") abort(1) end if
open_dll() returns 0, not -1, if it can't open the library.
public constant xSDL_Init = define_c_func(sdl,"SDL_Init",{C_UINT},C_INT),
define_c_func() returns -1 if it can't load that C function (which will definitely happen if you try to use a library that failed to open).
You need to add a check for this as well here.
public function SDL_Init(atom flags) return c_func(xSDL_Init,{flags}) end function
Finally, c_func() will crash if you use an invalid c routine id.
3. Re: Euphoria SDL2 Wrapper Error
- Posted by Lone_EverGreen_Ranger Jun 24, 2013
- 1373 views
Thank you Jim
It appears that Euphoria is unable to open the DLL. I'll look more into it.
4. Re: Euphoria SDL2 Wrapper Error
- Posted by ghaberek (admin) Jun 25, 2013
- 1374 views
Forked into: Extended dynamic linking routines
-Greg
5. Re: Euphoria SDL2 Wrapper Error
- Posted by mattlewis (admin) Jun 25, 2013
- 1352 views
Thank you Jim
It appears that Euphoria is unable to open the DLL. I'll look more into it.
Where is the dll? The easiest thing is to put it in the same directory as your interpreter (or your translated binary). That's the first directory that Windows searches when trying to open a dll. If it is in the same directory as your euphoria source, you may need to use an absolute path (which can be very fragile, of course).
Matt
6. Re: Euphoria SDL2 Wrapper Error
- Posted by Lone_EverGreen_Ranger Jun 25, 2013
- 1344 views
- Last edited Jun 26, 2013
Thank you Jim
It appears that Euphoria is unable to open the DLL. I'll look more into it.
Where is the dll? The easiest thing is to put it in the same directory as your interpreter (or your translated binary). That's the first directory that Windows searches when trying to open a dll. If it is in the same directory as your euphoria source, you may need to use an absolute path (which can be very fragile, of course).
Matt
The DLL is in the Euphoria/bin folder where the interpeter is located. I also have the DLL in the wrapper's directory as well. It appears it is not opening the dll for whatever reason. I'm not sure is it because the SDL2.DLL is a 32-bit/64-bit and not just 32-bit? As Euphoria can only open 32-bit DLLs?
EDIT: I got it to open the DLL. Now I just need to get some working examples.