Solved

Trouble with AfxBeginThread()

Posted on 2000-03-11
6
190 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 184
Looking for a specific application/software 2 109
How to determine file rename from EventLog ? 2 49
Change to event 1 111
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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