View previous topic :: View next topic |
Author |
Message |
Thorim
Joined: 21 Jul 2007 Posts: 1
|
Posted: Sat Jul 21, 2007 5:18 pm Post subject: Creating Thread with SDL |
|
|
Hi,
it's going fine with the SDL on D. But i have the Problem that i cannot create any thread with SDL.
i have tried the following
Code: | void* pDataReturn;
int test(void* inData ) {
return 0;
}
int function(void*) fp = &test;
SDL_CreateThread( fp, pDataReturn ); |
with the following compile error.
Code: | main.d(32): Error: cannot implicitly convert expression (fp) of type int(*)(void
*) to int(C *)(void*) |
What have i made wrong?
I'm will make thread of a member class to this way, if this is going to work. But is it possible at all? |
|
Back to top |
|
|
odeamus
Joined: 21 Feb 2006 Posts: 78 Location: Helsinki, Finland
|
Posted: Sun Jul 22, 2007 1:47 am Post subject: |
|
|
Try this:
Code: | extern(C) int test(void* inData ) |
All the SDL functions are C functions so you must treat them as such.
You can skip the function pointer stuff also.
Here's a complete test program which works on my XP box.
Code: |
module test.main;
import derelict.sdl.sdl;
import tango.io.Stdout;
static this()
{
DerelictSDL.load();
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
throw new Exception("Failed to load sdl");
}
}
static ~this()
{
SDL_Quit();
}
void main()
{
void *data;
SDL_Thread *thread = SDL_CreateThread(&test, data);
int status;
SDL_WaitThread(thread, &status);
Stdout("Status = ")(status).newline;
}
extern(C) int test(void *data)
{
return 2;
}
|
Should print out '2'. It uses Tango for I/O so, if you're Phobos user replace the relevant lines with Phobos equivalents.
O. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|