?
Solved

AfxBeginThread

Posted on 1997-01-05
1
Medium Priority
?
2,614 Views
Last Modified: 2013-11-20
JRUDD has helped to to realize that the prototype for a worker thread member function should be declared like this:

private:
static UINT TestThread( LPVOID );

and called like this:

 AfxBeginThread( TestThread, NULL );

I can not figure out what parameter I place in the body of TestThread. For example:

UINT  Nimzo::TestThread(  ???  )
{
      return 0;
}

What should I use to replace the question marks? Nothing I have tried has worked.

I'm using VC++ 4.0 Standard Edition.

Once again, your help is appreciated.
0
Comment
Question by:ldorfman
[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
 

Accepted Solution

by:
jrudd010197 earned 200 total points
ID: 1300093
Yes you can use a member function.  The way I show you is the most common way.

Make your member function static.  The reason for this is simple.  Every C++ member funcation has a hidden parameter - the "this" pointer.  Even though you don't pass it in it is there.  So here is a simple example of how to do it.

//header file
class CMyDialog : public CDialog
{
//regular CMyDialog stuff here

private:
//make it private so no one but this class can //use it
static UINT MyThreadProc( LPVOID );
};

void CMyDialog::OnMyFakeButtonClick()
{
     AfxBeginThread( MyThreadProc, NULL );
}

Now of course with the function being static that means you can't touch anything that is in your class that isn't static as well.  So to beat this you pass in the "this" pointer as your LPVOID parameter in AfxBeginThread.  

Of coures you can also use the other AfxBeginThread.  The one that takes a Runtime class pointer.  Then if you are using VC++ 4.2 inside your thread class you can use the macro ON_THREAD_MESSAGE.  This ( in my humble opinion ) is the cleanest and nicest way to do it.  Because to make the thread quit all you have to do is do this...

m_pThread->PostThreadMessage( WM_QUIT, 0, 0 );

Hope this helps
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

752 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