• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1277
  • Last Modified:

C++ Thread Example

Need Help Regarding Thread in c++.

Please anyone give me the example of creating Pointer to ResumeThread of CWinthread

Thanks in Advaced..
0
John-Paul75
Asked:
John-Paul75
  • 5
  • 4
  • 3
1 Solution
 
John-Paul75Author Commented:
Its C++
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Start a thread as suspended, so it doesn't run yet
 CWinThread* pThread = AfxBeginThread (ThreadFunc, ptp,THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);

Some code here to manipulate the information the thread will require to operate correctly

Now let the thread actually work
 pThread->ResumeThread ();
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
You could also look up MTRECALC in the help files.  It is an MFC example on using threads.  (I don't know if it actually uses ResumeThread but the other info may be worthwhile to look at).
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
sarabandeCommented:
if you mean function pointer it is

DWORD (CWinThread::*funcPtrResumeThread)() = &CWinThread::ResumeThread;

Sara




0
 
John-Paul75Author Commented:
No not like this something which include some overwriting of method.
0
 
sarabandeCommented:
ResumeThread is not a virtual function. you can overwrite it in your mfc application class which is derived from CWinThread but it won't be called from mfc framework.

you better explain what you intend to do. your keywords pointer, CWinThread, ResumeThread, overwriting don't give a senseful combination.

Sara
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
>>No not like this something which include some overwriting of method.

Do you mean writing the function the thread will use to do the processing?
If yes then you can look at the MFC example MTRECALC for instance or this article at Experts Exchange:

http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/A_3831-Sudoku-a-complete-MFC-application-Part-11.html

which uses a thread to perform a task and communicate with the main thread for display purposes.
0
 
John-Paul75Author Commented:
Thanks a lot but

Is their is any way to get the address of the CWinThread::ResumeThread() through respective DLL and store the address in a void pointer and resolve the reference by using late binding.

When I want to resume the thread I should use this pointer instead of ResumeThread();

Any Help in code format with explanation will appreciated.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Much simpler to store the pointer to the thread and call ResumeThread from that.
0
 
sarabandeCommented:
CWinThread::ResumeThread()  is a member function. you need two pointers - the pointer to the CWinThread instance and the pointer to the member function to be able to call it later. that isn't 'late binding' as you can't do a virtual call of a member function via pointer. moreover, ResumeThread is not a virtual function as already told.

Sara  
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
The reason given for deletion is self explanatory - nonsense.

I think the question has been adressed and answered/alternatives supplied.
0
 
John-Paul75Author Commented:
Sorry I was not really watching this question a long time after my posting
As I've solved my question.
So I would like to senior member please close this task.

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now