This is my problem. I have a GUI Visual C++ 6.0 application that runs as a service on XP and also listens on a port. Automatic startup. It needs to stay running even when the user is logged off. I reboot the system and I can connect to my service via a client on another computer. I can logon to the system where the service is running and all is fine. My icon is set into the system tray for access.

I have intercepted the WM_ENDSESSION / WM_QUERYENDSESSION messages and return 0 to say I have processed the WM_ENDSESSION. This works fine for the first logoff. I log back on and I see my service is still running and the icon is back on the system tray.

I try to logoff again and its like the system ignores it and stays logged on. If I shut my service down then I can logoff.

I have tried returning TRUE and FALSE for QUERYENDSESSION and neither works. Below is a snippet of code. Although WM_QUIT is in the compare list it isn't being sent because I was writing a log.txt file to see what was being processed.

LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
eespGlobal *pgbl;

if((message == WM_QUIT) ||
(message == WM_ENDSESSION) ||
(message == WM_QUERYENDSESSION))
{
pgbl = m_pTCmain->TcolGetGlobal();
if(pgbl->m_bServiceShutdown == TRUE)
{
return CFrameWnd::WindowProc(message, wParam, lParam);
}
else
{
if(message == WM_ENDSESSION)
{
return(0);
}

if(message == WM_QUERYENDSESSION)
{
return(FALSE);
}

return(TRUE);
}
}
return CFrameWnd::WindowProc(message, wParam, lParam);
}