• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

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
0
James Atkin
Asked:
James Atkin
1 Solution
 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now