Solved

Thread Basics

Posted on 2003-11-11
1
310 Views
Last Modified: 2013-11-20
I'm trying to start a thread in a class I've written using AfxBeginThread

What I want the thread to do is (almost) constantly monitor the status of another executable after I've started it.  The problem is, I can't figure out how to make AfxBeginThread work.

Here's the essence of my call:

void MyClass::StartThread()
{
this->monitorThread = AfxBeginThread(ThreadFunc,NULL,
THREAD_PRIORITY_NORMAL,0,0);
}


Then,
UINT MyClass::ThreadFunc(LPVOID p)
{
   //do stuff
}

I keep getting:
 error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'UINT (LPVOID)'

Any suggestions?  Thanks!

0
Comment
Question by:lakers2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
freewell earned 125 total points
ID: 9728085
The ThreadFunc needs to be a static or global function.

MyClass
{
    int nData;
    static UINT MyClass::ThreadFunc(LPVOID p);
}

void MyClass::StartThread()
{
    this->monitorThread = AfxBeginThread(ThreadFunc,this,THREAD_PRIORITY_NORMAL,0,0);
}

UINT MyClass::ThreadFunc(LPVOID p)
{
    MyClass* _this = (MyClass*)p;

    //do stuff
    _this->nData = 0;
}
0

Featured Post

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

623 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