Solved

AfxBeginThread

Posted on 1997-01-05
1
2,602 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 100 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
method notes when mouse over in eclipse 5 90
twoTwo  challenge 35 113
How to convert MFC::CString to UTF8 wchar_t* 10 384
Capture logon name 13 105
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 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