Click here to Skip to main content
15,917,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Any Ideas? Pin
Michael P Butler16-Apr-03 23:32
Michael P Butler16-Apr-03 23:32 
GeneralModifiying context menu of highlighted text Pin
nlyang16-Apr-03 20:35
nlyang16-Apr-03 20:35 
GeneralCrypto++ question Pin
DREVET Olivier16-Apr-03 19:44
DREVET Olivier16-Apr-03 19:44 
GeneralRe: Crypto++ question Pin
Zdeslav Vojkovic17-Apr-03 0:13
Zdeslav Vojkovic17-Apr-03 0:13 
GeneralRe: Crypto++ question Pin
DREVET Olivier17-Apr-03 1:20
DREVET Olivier17-Apr-03 1:20 
GeneralRe: Crypto++ question Pin
DREVET Olivier17-Apr-03 19:22
DREVET Olivier17-Apr-03 19:22 
GeneralMultithreading Problem Pin
16-Apr-03 18:09
suss16-Apr-03 18:09 
GeneralRe: Multithreading Problem Pin
Joe Woodbury16-Apr-03 19:00
professionalJoe Woodbury16-Apr-03 19:00 
First, you should be using _beginthreadex() since you are using the CRT.

You also need to pass a "static" function address to _beginthreadex() and, in this situation, pass this as the argument to the newly created thread. Inside the thread function, using the pointer to the class to call the classes "Thread" routine.

A code snippet for my thread base class:

This is from the .h file (heavily stripped down. If it isn't already obvious, you derive a new class from CBThread and provide a ThreadMain() member function.):

typedef unsigned (__stdcall *PCBTHREAD_FUNCTION)(void *);

class CBThread : public CBHandle
{
public:
	virtual unsigned ThreadMain() = 0;

public:
	CBThread()	{}

	BOOL Create(
		PCBTHREAD_FUNCTION pThread,
		LPVOID pParam = NULL,
		unsigned stackSize = 0,
		BOOL startSuspended = FALSE,
		int priority = -1);

	BOOL Create(
		unsigned stackSize = 0,
		BOOL startSuspended = FALSE,
		int priority = -1);
};


This is from the .cpp file:

static unsigned __stdcall CBThreadThread(CBThread *pClass)
{
	return pClass->ThreadMain(); // ThreadMain is a the virtual public function in the CBThread class
}

BOOL CBThread::Create(
	PCBTHREAD_FUNCTION pThread,
	LPVOID pParam,
	unsigned stackSize,
	BOOL startSuspended,
	int priority)
{
	if (IsRunning())
		return FALSE;

	unsigned threadID; // it's useless so throw it away and save space
	if ((m_handle = (HANDLE) _beginthreadex(NULL, stackSize, pThread, pParam, startSuspended, &threadID)) != NULL)
	{
		if (priority >= 0)
			SetPriority(priority);
		return TRUE;
	}
	return FALSE;
}

BOOL CBThread::Create(
	unsigned stackSize,
	BOOL startSuspended,
	int  priority)
{
	return Create((PCBTHREAD_FUNCTION)CBThreadThread, this, stackSize, startSuspended, priority);
}

Questionhow to get handle Pin
Prog Mmer16-Apr-03 17:23
Prog Mmer16-Apr-03 17:23 
GeneralBasic iphlpapi questions Pin
autekre16-Apr-03 16:57
autekre16-Apr-03 16:57 
QuestionThere is problem,I write a small demo project for demonstrate this problem,who has clue to solve the problem? Pin
Jeef16-Apr-03 16:36
Jeef16-Apr-03 16:36 
GeneralQuestions on behavior of code Pin
yukikyo16-Apr-03 16:16
yukikyo16-Apr-03 16:16 
Generalanyone know of a free utility that can... Pin
Roman Nurik16-Apr-03 15:09
Roman Nurik16-Apr-03 15:09 
GeneralRe: anyone know of a free utility that can... Pin
Nish Nishant16-Apr-03 19:06
sitebuilderNish Nishant16-Apr-03 19:06 
GeneralRe: anyone know of a free utility that can... Pin
Joan M16-Apr-03 21:52
professionalJoan M16-Apr-03 21:52 
GeneralMFC & MDI Pin
Brian Shifrin16-Apr-03 14:54
Brian Shifrin16-Apr-03 14:54 
GeneralRe: MFC & MDI Pin
Brian Shifrin16-Apr-03 14:56
Brian Shifrin16-Apr-03 14:56 
Generalglobal variables Pin
Gabor Kalman16-Apr-03 13:34
Gabor Kalman16-Apr-03 13:34 
GeneralRe: global variables Pin
Maximilien16-Apr-03 13:50
Maximilien16-Apr-03 13:50 
GeneralRe: global variables Pin
Taka Muraoka16-Apr-03 13:56
Taka Muraoka16-Apr-03 13:56 
GeneralRe: global variables Pin
Christian Graus16-Apr-03 14:14
protectorChristian Graus16-Apr-03 14:14 
Generalstatic libraries Pin
jason9916-Apr-03 12:46
jason9916-Apr-03 12:46 
GeneralSetPaneText not working Pin
jcjollant16-Apr-03 12:16
jcjollant16-Apr-03 12:16 
GeneralUsing Custom Classes in AFX message maps Pin
Anonymous16-Apr-03 10:07
Anonymous16-Apr-03 10:07 
GeneralRe: Using Custom Classes in AFX message maps Pin
Nitron16-Apr-03 16:10
Nitron16-Apr-03 16:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.