Dear everyone, I am writing a singleton class to manage a thread, here's the code:
#include <windows.h>
typedef class MsgListener
{
private:
HANDLE _threadHandle;
DWORD _threadId;
static MsgListener *_instance;
MsgListener();
DWORD WINAPI Listen(LPVOID param);
public:
static MsgListener *GetInstance();
void StartListen();
void StopListen();
} MSGLISTENER, *LPMSGLISTENER;
MsgListener *MsgListener::_instance = new MsgListener();
MsgListener::MsgListener()
{
_threadHandle = 0;
_threadId = 0;
}
DWORD WINAPI MsgListener::Listen(LPVOID param)
{
// The method to run in a new thread....
}
MsgListener *MsgListener::GetInstance()
{
if (!_instance)
_instance = new MsgListener();
return _instance;
}
void MsgListener::StartListen()
{
// Here, the compiler give the error:
// cannot convert 'MsgListener::Listen' from type 'DWORD (MsgListener::)(LPVOID) { aka long unsigned int (MsgListener::)(void*) }' to type 'LPTHREAD_START_ROUTINE { aka long unsigned int (__attribute__((__stdcall__)) *)(void*) }'
this->_threadHandle = CreateThread(NULL, 0, Listen, 0, &_threadId);
}
void MsgListener::StopListen()
{
CloseHandle(_threadHandle);
}
The ide I use is Code::Blocks and the compiler is GNU GCC COMPILER.
How to convert the function pointer in a class to the normal function pointer in C? And I really don't know the difference between these two kind of function pointers. Where does each kind of function pointer save in the memory?