im not sure how to use this properly any one got some advice?
#pragma once
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
class cThread
{
protected:
HANDLE d_threadHandle;
DWORD d_threadID;
bool d_bIsRunning;
public:
cThread();
virtual ~cThread();
void Begin();
void End();
bool IsRunning();
virtual DWORD ThreadProc();
};
#include"cThread.h"
cThread::cThread()
{
d_threadID = 0;
d_threadHandle = NULL;
d_bIsRunning = false;
}
cThread::~cThread()
{
End();
}
void cThread::Begin()
{
#if defined( _WIN32 ) && defined( _MT )
if( d_threadHandle )
End(); // just to be safe.
// Start the thread.
d_threadHandle = CreateThread( NULL,
0,
(LPTHREAD_START_ROUTINE)cThreadProc,
this,
0,
(LPDWORD)&d_threadID );
if( d_threadHandle == NULL )
{
// Arrooga! Dive, dive! And deal with the error, too!
}
d_bIsRunning = true;
#endif
}
DWORD cThread::ThreadProc()
{
return 0;
}
static DWORD WINAPI cThreadProc( cThread *pThis )
{
return pThis->ThreadProc();
}
void cThread::End()
{
#if defined( _WIN32 ) && defined( _MT )
if( d_threadHandle != NULL )
{
d_bIsRunning = false;
WaitForSingleObject( d_threadHandle, INFINITE );
CloseHandle( d_threadHandle );
d_threadHandle = NULL;
}
#endif
}
bool cThread::IsRunning()
{
return(d_bIsRunning);
}
#include<iostream.h>
#include"mThread.h"
mThread::mThread()
{
mData = 0;
}
void mThread::add(int amount = 1)
{
mData += amount;
}
mThread::~mThread()
{
End();
}
DWORD mThread::ThreadProc()
{
this->add();
cout<<mData<<endl;
return 0;
}
#include"cThread.h"
class mThread : public cThread
{
public:
mThread();
~mThread();
DWORD ThreadProc();
void add(int amount);
int mData;
};
#include"mThread.h"
#include<iostream.h>
void main()
{
mThread *x = new mThread;
cThread *q = new mThread;
cout<<"hello"<<endl;
x->Begin();
cout<<x->mData<<endl;
q->Begin();
}
im not sure how to get it working so that begin actually starts the thread, which should increment mData then output it then end.
the cThread class is originally from FlipCode so it should work i just dont knwo hwo to get it working.