Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling method of a class from call back function ??

Posted on 1998-09-18
1
Medium Priority
?
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

721 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