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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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
MadshiCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
afzaljAuthor Commented:
Doh ! Why didn't I think of the first Idea (find 'n' bind !). Cheers Madshi.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.