Solved

Trouble with AfxBeginThread()

Posted on 2000-03-11
6
193 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
Technology Partners: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

680 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