Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calling method of a class from call back function ??

Posted on 1998-09-18
1
Medium Priority
?
186 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

971 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