How do I call a member function as a thread in MFC6?

HI all,

I have an application that during startup, needs to kick off a function as a thread. This function needs to execute and once complete, die.

I currently have the following :

UINT CMyApp::pThreadDoIt(LPVOID pParam)
{
     // Do stuff;
     return 0;
}

In the main startup function, I have the following line:
    AfxBeginThread( pThreadDoIt );

When I compile, I get the error :
'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'

Please help!!!!!!!

Thanks,

James
LVL 4
James AtkinSenior Principle Software EngineerAsked:
Who is Participating?
 
alb66Commented:
1. If the thread function ( pThreadDoIt ) belong to a task (as in your case) it must be declared "static".

in MyApp.h:

  static UINT pThreadDoIt(LPVOID pParam);


2. You must pass a second parameter to AfxBeginThread (the parameter for the thread function).

  AfxBeginThread( pThreadDoIt, NULL );

0
 
James AtkinSenior Principle Software EngineerAuthor Commented:
Great! Thanks...
Completely missed that! :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.