Solved

Thread Basics

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

920 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

18 Experts available now in Live!

Get 1:1 Help Now