Solved

Calling method of a class from call back function ??

Posted on 1998-09-18
1
180 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

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
substring method in java 1 119
method notes when mouse over in eclipse 5 86
NotAlone Challenge 20 83
Bartender label printing - switch on and off graphics 3 38
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

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