Solved

Thread Basics

Posted on 2003-11-11
1
308 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 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