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
Solved

Trouble with AfxBeginThread()

Posted on 2000-03-11
6
192 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Suggested Solutions

Title # Comments Views Activity
has22 challenge 11 104
Modbus - whats the maximum I can store in one register? 4 80
mapBully challenge 6 152
mapAB Challlenge 35 156
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

856 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