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

Posted on 2009-04-28
Last Modified: 2013-11-20
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!!!!!!!


Question by:jatkin
    LVL 19

    Accepted Solution

    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 );

    LVL 4

    Author Comment

    Great! Thanks...
    Completely missed that! :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
    Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This video discusses moving either the default database or any database to a new volume.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now