Thanks for your comments and suggestions. Yes, I think your second point is the problem as well - although the program has got a load of other problems besides, now that I've had time to look more closely through the code to try to understand the flow. I have never seen anything like it. I'm doing a complete redesign and c++ coding from the ground up - it's so bad!! I have found this (below). I don't know whether to laugh or cry. I thought you might get a smile from it. Please feel free to pass to other colleagues for a laugh
.
In WinMain function before message loop
Code:
//Start heartbeat
_beginthread(StatusCheck, 0, NULL);
In WinMain message loop
Code:
//Timer for heartbeat
case WM_TIMER:
if (p_wParam == TIM_STATS) {
StatusSet();
}
break;
Code:
//Thread for status check for heartbeat
VOID StatusCheck(PVOID p_void)
{
while (TRUE) {
EnterCriticalSection(&l_statcheck);
l_State = TRUE;
LeaveCriticalSection(&l_statcheck);
SetTimer(g_hmain, TIM_STATS, 4000, NULL);
Sleep(6000);
EnterCriticalSection(&l_statcheck);
if (l_State == TRUE) {
exit(ShowError(ERR_HEARTBEAT));
}
LeaveCriticalSection(&l_statcheck);
/*if (l_State == TRUE) {
DisplayMessage("Problem with heart-beat!");
}*/
//Check to make sure global variables OK
if (g_lastone != INT_MAX) {
exit(ShowError(ERR_ZERO));
}
}
}
//Clear state flag to indicate heartbeat running
void StatusSet(void)
{
KillTimer(g_hmain, TIM_STATS);
EnterCriticalSection(&l_statcheck);
l_State = FALSE;
LeaveCriticalSection(&l_statcheck);
return;
}
g_lastone is the last global variable to be declared and is assigned at the start of WinMain
Code:
g_lastone = INT_MAX; //Special one to make sure not overwriting global variables
I think on balance I'll cry
Is the programmer who wrote this **** certifiably insane??? Why did I agree to have a 'quick' look at this garbage???