Solved

Calling method of a class from call back function ??

Posted on 1998-09-18
1
182 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 111
how to monitor remote shell execution on linux 9 104
zeroFront challenge 7 114
Increment column based of a FK 8 32
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

820 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