Re: Threads
PD: Testing with a UI thread I get this error:
MyThread.obj : error LNK2001: unresolved external symbol "protected:
void __thiscall MyThread::MyMessageHandler(unsigned int,long)" (?
MyMessageHandler@MyThread@@IAEXIJ@Z)
Debug/thread 2.exe : fatal error LNK1120: 1 unresolved externals
I defined a Message in MyThread.cpp:
BEGIN_MESSAGE_MAP(MyThread, CWinThread)
//{{AFX_MSG_MAP(MyThread)
// NOTE - the ClassWizard will add and remove mapping macros here.
ON_THREAD_MESSAGE( WM_MYTHREAD_MESSAGE, MyMessageHandler)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
And MyMessageHandler function is this (in MyThread.cpp):
void MyMessageHandler( WPARAM wParam, LPARAM lParam )
{
TRACE("Thread::MyMessageHandler.\n");
}
It's prototipe in MyThread.h:
// Implementation
protected:
virtual ~MyThread();
void MyMessageHandler( WPARAM wParam, LPARAM lParam );
// Generated message map functions
//{{AFX_MSG(MyThread)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
I created the thread:
(MyThread*) pMyThread = (MyThread*)
AfxBeginThread( RUNTIME_CLASS( MyThread ), THREAD_PRIORITY_NORMAL, 0,
CREATE_SUSPENDED );
And started:
pMyThread->ResumeThread();
And finally I made a button that sends a message to the thread:
void CThread2Dlg::OnButton3()
{
// TODO: Add your control notification handler code here
pMyThread->PostThreadMessage( WM_MYTHREAD_MESSAGE, 0, 0 );
}