You must define your callback function as a static function if it is a member function!
Better Design: Define a Reusable Class!
From my previous answer : (with slight changes)
Even better would be to define a reusable class with a pure virtual function run() , which will be implemented by derived stream classes. Here's how it should be designed:
//runnable is reusable class. All thread classes must derive from it! class runnable { public: virtual ~runnable() {} static DWORD WINAPI run_thread(LPVOID args) { runnable *prunnable = static_cast<runnable*>(args); return prunnable->run(); } protected: virtual DWORD run() = 0; //derived class must implement this! }; class Thread : public runnable //derived from runnable! { public: void newthread() { CreateThread(NULL, 0, &runnable::run_thread, this, 0, NULL); } protected: DWORD run() //implementing the virtual function! { /*.....your thread execution code.....*/ } }
Nawaz
source share