C++ Class wrapper on top of WinMain/DllMain 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-&gt;Init();
    else
        _ThisInit-&gt;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-&gt;Check(true); // So Init gets called
}

void HandleExit()
{
    _Init-&gt;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
it's better to explicitly call init and exinit than pass a bool to "Check" to say which will one will get called.  maybe call them "Start" and "Exit"

Also, I'd suggest not making them virtual, if you want to be able to extend it...use a protected virtual

public: bool Start();
protected: virtual bool StartImpl();


void CInit::Start()
{
   StartImpl();
}


This gives you a bit more control over the calling in to your API.  (Also a mostly recommended best practice for C++). 

It's called "Non Virtual Interface" or NVI.  It does have pros and cons.  But in this case I think it would be quite useful.