Solved

Trouble with AfxBeginThread()

Posted on 2000-03-11
6
197 Views
Last Modified: 2013-11-20
I am trying to use a worker thread on occasion in my app, that would perform a little simple task that I'd like to run concurrently.  I don't see any real synchronization problems, so it would seem to be an ideal function to thread.  However, I cannot get AfxBeginThread() to properly execute.  In the documentation, there is the following example:

******************************
UINT MyThreadProc( LPVOID pParam ) {
    CMyObject* pObject = (CMyObject*)pParam;
    if (pObject == NULL || !pObject->IsKindOf(RUNTIME_CLASS(CMyObject)))
    return -1;    // illegal parameter    // do something with 'pObject'
    return 0;    // thread completed successfully}

// inside a different function in the program...pNewObject = new CMyObject;
AfxBeginThread(MyThreadProc, pNewObject);
************************************

This all seems pretty straightforward.  However, it does not work.  There is one difference- I need to use this within a class.  So MyThreadProc, in my example, would be MyClass::MyThreadProc.  I'm not sure if this is the reason it doesn't run (I get message "neither of the 2 overloads can convert parameter 1 from UINT VOID *")

Does anyone know how to actually do this properly?  And how to run it from within a class?

Thanks.

0
Comment
Question by:Mournblade
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
nutsnuts earned 75 total points
ID: 2607378
Usually, we use a global function as the worker thread fucntion. Anyway, if you want to  run it from within a class, you can just use a STATIC member function. And I think it's the only way, Because AfxBeginThread need a global function pointer.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2607635
or friend.
0
 

Author Comment

by:Mournblade
ID: 2608895
Thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Mournblade
ID: 2608899
Hey, nutsnuts- let me know if you got the 75 pts.  I thought that's what I posted, but the top of this page now says 7.  ??
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2608917
Mournblade,the 7 is the cost other people should pay to read a valued question ,10% of original points.And nutnuts got depends on the grade you give,if it's "A",nutnuts got 4*points,'B' ,3*points....
Points here equal 75.

Regards
W.Yinan
0
 
LVL 1

Expert Comment

by:nutsnuts
ID: 2608969
Mournblade, Thanks. I've got 225 points and a grade of "B".

Regards
nutsnuts
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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…
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 we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

687 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