Skip to main content
gamedev.net
🔒 Locked

boost binding member function as Win32 thread function

Started by dcosborn 4 replies 1k views
Original Post
dcosborn
dcosborn
I'm trying to bind a member function as a Win32 thread function type so I can pass it to CreateThread. From what I understand from the boost.bind doc, it should be done like this: struct MsThread { DWORD WINAPI Mediary(LPVOID); DWORD _threadId; }; MsThread thread; CreateThread(NULL, 0, boost::bind< DWORD WINAPI >(&MsThread::Mediary, &thread, _1), 0, &thread._threadId); However, it gives me errors. I'm using MinGW g++ 3.2.3 WinXP. Thanks for any help. [edited by - dcosborn on January 27, 2004 8:18:46 AM]
Fruny
Fruny
CreateThread expects a plain C function pointer.
boost::bind returns a boost::function object.

No cigar.

boost::thread will happily accept boost::function (and other) objects


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
glassJAw
glassJAw
quote:
Original post by daerid
Fruny''s sig is awesome


daerid | Legends | Garage Games | Spirit | Hapy | Boost | Python | Google
"Doomed to crumble, unless we grow, and strengthen our communication" - Maynard James Keenan, Tool


I give it 8.5/10

8 because it''s awesome, and an extra 0.5 because it''s fairly small.
parla
parla
Why dont you use boosts threads aswell?

class Class
{
public:
void run();
}

Class obj;

boost::thread t(boost::bind(&Class::memberfunc, &obj));

or:

void run();

boost::thread t(run);

Much nicer, and portable too!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.