I'm trying to create a thread in a dialog based app. In my dialog class I
have a handler OnPlay() that
I called when a button is pressed. This handler creates a thread an calls
another function to execute in that
thread. However, this will not compile.
void CDlgMyDlg::OnPlay()
{
CWinThread *myThread;
myThread = AfxBeginThread(PlayThread, NULL);
}
UINT CDlgMyDlg::PlayThread(LPVOID pParam)
{
// Do stuff...
return 0;
}
The error I get is
error C2665: 'AfxBeginThread' : none of the 2 overloads can convert
parameter 1 from type 'unsigned int (void *)'
However, according to the documentation, I've declared my controlling
function PlayThread correctly. The documentation specifies that the
controller function signature should be
UINT MyControllingFunction( LPVOID pParam );
Any ideas?
Wayne.
Cheers
Check Abdoul
-------------------
"Wayne Leone" <wa...@funcom.ie> wrote in message
news:9a21un$9jf$1...@saille.funcom.ie...
Yes it does....but with one exception, your threadfunction is member of a
class, there for it is not STATIC, wich it should be. If you want your
threadfunction to be part of a class you have to declare it static. The
consequence is that you can not access member variables that is not static.
To solve this you can do like this:
Decleare one static thread function:
static UINT MyStaticControllingFunction( LPVOID pParam );
and one non static
UINT MyControllingFunction( );
in the static function call the none static function through the pParam,
send (this) as the thread parameter. myThread = AfxBeginThread(PlayThread,
this);
((CDlgMyDlg*)pParam)->MyControllingFunction();
and you are all set!
Wayne.
"Rickard" <rickard...@now.se> wrote in message
news:3AC49D74...@now.se...