Solved

Trouble with AfxBeginThread()

Posted on 2000-03-11
6
185 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

27 Experts available now in Live!

Get 1:1 Help Now