Solved

Calling method of a class from call back function ??

Posted on 1998-09-18
1
174 Views
Last Modified: 2013-11-19
i need to call a function (which is a public memeber of say CMyClass) in a call back function (of a thread)

i am new to VC++ so excuse me if its a stupid question ....

thanks in advance !
0
Comment
Question by:kashif063098
1 Comment
 
LVL 1

Accepted Solution

by:
VAM345 earned 40 total points
ID: 1322314
First you need to define prototipe of you member function
  typedef BOOL (CMyClass::*PFMy)(BOOL); 

define follow class
class CMyThreadParam
{
  CMyClass* m_pMyClass;
  PFMy m_pfMy;
};

Writing you working thread function in that way
UINT MyThreadFn(LPVOID pParam)
{
  CMyThreadParam* pMyThreadParam = (CMyThreadParam*) pParam;
  // do someting;

  // Call you member function
  BOOL bRes = (pMyThreadParam->m_pMyClass->*
               pMyThreadParam->m_pfMy)(TRUE);

  // do someting;

  return 0;
}

To start thread function do this in CMyClass

In some function do this to start thread.
  CMyThreadParam* pMyThreadParam = new CMyThreadParam();
  pMyThreadParam->m_pMyClass = this;
  pMyThreadParam->m_pfMy = (PFMy)&CMyClass::MyMember;
That call return immediately(not forget this).
  AfxBeginThread(MyThreadFn, (LPVOID) pMyThreadParam);

Do not forget to call this after thread leave
  delete pMyThreadParam;

So excuse me for my very bad English.
I hope so that help you. To answer send mail in victor_milev@hotmail.com
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video discusses moving either the default database or any database to a new volume.

706 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

20 Experts available now in Live!

Get 1:1 Help Now