Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Compiler error with AfxBeginThread()

1 view
Skip to first unread message

Wayne Leone

unread,
Mar 30, 2001, 9:37:08 AM3/30/01
to
Hi,

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.


Check Abdoul

unread,
Mar 30, 2001, 9:48:28 AM3/30/01
to
Hi..
Your PlayThread function should be a defined as a static
function.

Cheers
Check Abdoul
-------------------

"Wayne Leone" <wa...@funcom.ie> wrote in message
news:9a21un$9jf$1...@saille.funcom.ie...

Rickard

unread,
Mar 30, 2001, 9:51:32 AM3/30/01
to

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 Leone

unread,
Mar 30, 2001, 10:18:16 AM3/30/01
to
Thanks guys, that worked a treat!.

Wayne.

"Rickard" <rickard...@now.se> wrote in message
news:3AC49D74...@now.se...

0 new messages