When Win95/98 quits.....

....How can I quit an application when Win95/98 is about to shutdown or log-off ? The application has no window handles associated with it, and I do not want to hook window calls to see whether a WM_QUERYENDSESSION OR WM_ENDSESSION message has been sent. Basically, it is a multithreaded application and it needs to terminate when the user has logged off or the computer is being shutdown. Is there any other way of doing this ? (It needs to be a clean method ! No dodgy code !, pref. in c plz. or any ideas would be appreciated...).
Thanx, Afzal.
afzaljAsked:
Who is Participating?
 
MadshiConnect With a Mentor Commented:
How about a different solution? You could bind your program to the explorer? You could run a thread that calls WaitForSingleObject(explorerProcessHandle, ...) and then terminate your program when this Wait call returns.

Yes, there IS a way to overcome the event problem. Use a named event, create it in your application and open it in every hook dll (CreateEvent/OpenEvent), then it should work without any problems...

Regards, Madshi.
0
 
MadshiCommented:
Well, if you want a *clean* way, I think you can't get around creating a window, that then can handle the WM_QUERYENDSESSION and WM_ENDSESSION messages.

Regards, Madshi.
0
 
MadshiCommented:
Hmmm... BUT... AFAIK, Win9x stops all programs automatically, when the user logs off or Win is shut down, except when your program calls RegisterServiceProcess...
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
afzaljAuthor Commented:
It doesent seem to quit my program. (It Sleep for INFINITE). I don't really want a window because it is then easily hackable (i've found).
0
 
afzaljAuthor Commented:
It also uses RegisterServiceProcess and Re-address Process32First in the kernel32.dll.
0
 
alexoCommented:
What's so hackable about a simple message loop that only checks WM_QUERYENDSESSION?
0
 
afzaljAuthor Commented:
Basically, if a programmer can get the handle of my window (by enumerating or something...) he/she can then kill the window or send a simple WM_QUERYENDSESSION message, and my program will die. Also, they could kill the window which would result in my program not functioning correctly. I've had trouble using windows before and I've decided that i'm coding the app without windows.
0
 
afzaljAuthor Commented:
Also, IF I do hook, as soon as a WM_QUERYENDSESSION message is found, I want the hook to signal a flag to end the process e.g.

{inside hook}:
if (cwp->message == WM_QUERYENDSESSION)
     SetEvent(termprog);

where termprog is a CreateEvent object which has been defined outside of the hook procedure. However, this doesnt work because the hook is in a context of it's own (i've found ?).Hence, the end of my process looks like..

WaitForSingleObject(termprog, INFINITE);
But termprog does not become set by the hook proc.
0
 
afzaljAuthor Commented:
Also, IF I do hook, as soon as a WM_QUERYENDSESSION message is found, I want the hook to signal a flag to end the process e.g.

{inside hook}:
if (cwp->message == WM_QUERYENDSESSION)
     SetEvent(termprog);

where termprog is a CreateEvent object which has been defined outside of the hook procedure. However, this doesnt work because the hook is in a context of it's own (i've found ?).Hence, the end of my process looks like..

WaitForSingleObject(termprog, INFINITE);
But termprog does not become set by the hook proc.Is there anyway of overcoming this ?
0
 
afzaljAuthor Commented:
Doh ! Why didn't I think of the first Idea (find 'n' bind !). Cheers Madshi.
0
All Courses

From novice to tech pro — start learning today.