Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

AfxBeginThread

Posted on 1997-01-05
1
Medium Priority
?
2,617 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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 …
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

636 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