Solved

Thread controlling function as non-global

Posted on 1998-10-27
3
409 Views
Last Modified: 2013-11-20
I am using Visual c++ 5 to join two previous c++ programs and am using multithreading to let them run simultaneously.

I have built the GUI in a project and would like to add the other program to run as a worker thread when required.

I wan't the worker thread to have access to members of MFC classes in the original GUI thread. The problem I am having is in calling the worker thread from within a member function of the GUI thread.

I am trying to do this with code like this:

AfxBeginThread( (AFX_THREADPROC ) CMatchThread::MatchThreadProc, m_pPose);

where the actual controlling function is defined in the CMatchThread class as follows:

static UINT MatchThreadProc(LPVOID);

The error I get is this:
error C2440: 'type cast' : cannot convert from 'overloaded function type' to 'unsigned int (__cdecl *)(void *)'
                                                     None of the functions with this name in scope match the target type

I can't understand what's wrong with my typecast, I know it's possible to declare the controlling function as a non-global, where am I going wrong?
0
Comment
Question by:gavinpat
3 Comments
 

Expert Comment

by:kahhoe
ID: 1323897
hi gavinpat,

If I remember correctly, thread only work with C functions.  There are issue like stack and heap size to set too.  

One solution is to create a C function thread to run your class functions.  For example,

threadfunc1()
{
  CMatchThread::MatchThreadProc();  
}

Try to look for ACE (Adaptive Communication Envirnoment, I think) for information on how to implement multi-thread class.  Or just buy thread.h++ from roguewave.



Best Regards,
Kah Hoe
0
 
LVL 1

Accepted Solution

by:
Bridge earned 100 total points
ID: 1323898
Pass the class object as the parameter to the thread function.
0
 

Author Comment

by:gavinpat
ID: 1323899
Bridge, surely passing the class object as the parameter would mean that the thread becomes a GUI thread instead of a worker thread? I don't really want the overhead of a message pump slowing down the rest of the program.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

22 Experts available now in Live!

Get 1:1 Help Now