I've written some code to do the job for me. The final results seems to work fine, but I would like to know if this is how I should Handle classes. And where I can improve or things which are just plain stupid.
class CInit
{
public:
CInit();
~CInit();
void Check(bool);
virtual bool Init();
virtual bool ExInit();
private:
static CInit* _ThisInit;
};
CInit* CInit::_ThisInit;
CInit::CInit()
{
if(_ThisInit == 0)
_ThisInit = this;
}
CInit::~CInit()
{
}
void CInit::Check(bool bStart)
{
if(bStart)
_ThisInit->Init();
else
_ThisInit->ExInit();
}
bool CInit::Init()
{
return true;
}
bool CInit::ExInit()
{
return true;
}
This is my cInit class, as you may see this has a static value, because in when the program execetues it will first run the global class instance which will be used like this. It will overload Init() and there the program starts.
CRaPE mycp;
bool CRaPE::Init()
{
return true;
}
bool CRaPE::ExInit()
{
return true;
}
The program runs from here:
CInit* _Init;
void HandleStartUp()
{
_Init = new CInit();
_Init->Check(true); // So Init gets called
}
void HandleExit()
{
_Init->Check(false); // so ExInit gets called
delete _Init;
}
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpReserved )
{
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
{
HANDLE hThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)HandleStartUp,0,0,0);
if(hThread == 0)
return false;
}
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
HandleExit();
break;
}
return TRUE;
}
I hope I explained well, thanks for reading.
Gz