From: Hugo gleaves on
I'm a little surprised at something, it seems there is now way (no Win32
function) to ask windows if a shutdown has been issued.

I'd very much like ask the OS this question before I allow an app to call
some other functions in a support library.

The library updates mapped memory in all sorts of complicated ways.

If a process is inside one of these update functions, partway through its
work and the OS bluntly kills the app, then the mapped data will be flushed
to disk OK but may be corrupt because the update function was interrupted.

These functions execute very very rapidly, but there is always a "window"
for failure.

So I want to put code into these update functions that (in essence) does this:

if (OsShutdownInProgress == FALSE)
{
do the fiddly update logic.
}
else
return(OPERATION_PREVENTED_DUE_TO_OS_SHUTDOWN);

This greatly reduces the window, so that in almost all cases we will get a
clean failure in the update functions if user's app ignores shutdown and
updates the mapped data via our API.

But is there such a function?

Is there any sort of info struct we can get from Windows, with a flag
indicating that a shutdown has been started?

Thanks
H
From: Kerem Gümrükcü on
Hi Hugo,

you dindt say what kind of application you are running
so i will tell you some ways this can be aquired/notfied:

WM_QUERYENDSESSION //windowed applications
HandlerRoutine Callback Function //console based
RegisterServiceCtrlHandlerEx Function //service based

Each of them will give you a "callback" whenever windows
is shutting down or a session changes. Whenever you get
a notification, then set some global flag indicating a shutdown
and check the flag before you make any calls,..

You see there are many ways,... ;)

regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------

"Hugogleaves(a)hotmail.com>" <hugh<underbar> schrieb im Newsbeitrag
news:3F82C790-8545-4DC8-98A7-970E2193C9CB(a)microsoft.com...
> I'm a little surprised at something, it seems there is now way (no Win32
> function) to ask windows if a shutdown has been issued.
>
> I'd very much like ask the OS this question before I allow an app to call
> some other functions in a support library.
>
> The library updates mapped memory in all sorts of complicated ways.
>
> If a process is inside one of these update functions, partway through its
> work and the OS bluntly kills the app, then the mapped data will be
> flushed
> to disk OK but may be corrupt because the update function was interrupted.
>
> These functions execute very very rapidly, but there is always a "window"
> for failure.
>
> So I want to put code into these update functions that (in essence) does
> this:
>
> if (OsShutdownInProgress == FALSE)
> {
> do the fiddly update logic.
> }
> else
> return(OPERATION_PREVENTED_DUE_TO_OS_SHUTDOWN);
>
> This greatly reduces the window, so that in almost all cases we will get a
> clean failure in the update functions if user's app ignores shutdown and
> updates the mapped data via our API.
>
> But is there such a function?
>
> Is there any sort of info struct we can get from Windows, with a flag
> indicating that a shutdown has been started?
>
> Thanks
> H

From: Hugo gleaves on

Thanks Kerem

I was thinking along similar lines, then I just noticed that
GetSystemMetrics can be invoked with SM_SHUTDOWN.

This will return non-zero if the system is in the process of shutting down.

Unless I'm mistaken, this is just what I need.

Thx

H


"Kerem Gümrükcü" wrote:

> Hi Hugo,
>
> you dindt say what kind of application you are running
> so i will tell you some ways this can be aquired/notfied:
>
> WM_QUERYENDSESSION //windowed applications
> HandlerRoutine Callback Function //console based
> RegisterServiceCtrlHandlerEx Function //service based
>
> Each of them will give you a "callback" whenever windows
> is shutting down or a session changes. Whenever you get
> a notification, then set some global flag indicating a shutdown
> and check the flag before you make any calls,..
>
> You see there are many ways,... ;)
>
> regards
>
> Kerem
>
> --
> -----------------------
> Beste Grüsse / Best regards / Votre bien devoue
> Kerem Gümrükcü
> Latest Project: http://www.pro-it-education.de/software/deviceremover
> Latest Open-Source Projects: http://entwicklung.junetz.de
> -----------------------
>
> "Hugogleaves(a)hotmail.com>" <hugh<underbar> schrieb im Newsbeitrag
> news:3F82C790-8545-4DC8-98A7-970E2193C9CB(a)microsoft.com...
> > I'm a little surprised at something, it seems there is now way (no Win32
> > function) to ask windows if a shutdown has been issued.
> >
> > I'd very much like ask the OS this question before I allow an app to call
> > some other functions in a support library.
> >
> > The library updates mapped memory in all sorts of complicated ways.
> >
> > If a process is inside one of these update functions, partway through its
> > work and the OS bluntly kills the app, then the mapped data will be
> > flushed
> > to disk OK but may be corrupt because the update function was interrupted.
> >
> > These functions execute very very rapidly, but there is always a "window"
> > for failure.
> >
> > So I want to put code into these update functions that (in essence) does
> > this:
> >
> > if (OsShutdownInProgress == FALSE)
> > {
> > do the fiddly update logic.
> > }
> > else
> > return(OPERATION_PREVENTED_DUE_TO_OS_SHUTDOWN);
> >
> > This greatly reduces the window, so that in almost all cases we will get a
> > clean failure in the update functions if user's app ignores shutdown and
> > updates the mapped data via our API.
> >
> > But is there such a function?
> >
> > Is there any sort of info struct we can get from Windows, with a flag
> > indicating that a shutdown has been started?
> >
> > Thanks
> > H
>
> .
>
From: Kerem Gümrükcü on
Hi,

if this is good for you,
then take it, but i would
use the callbacks because
once they have been implemented,
they will give you more options
on detecting "what" exactly lead
windows to a session change, so
this is more expandable,...

regards

K.

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------

"Hugogleaves(a)hotmail.com>" <hugh<underbar> schrieb im Newsbeitrag
news:37BB2C78-E285-4BD1-B771-E125AD95D968(a)microsoft.com...
> Thanks Kerem
>
> I was thinking along similar lines, then I just noticed that
> GetSystemMetrics can be invoked with SM_SHUTDOWN.
>
> This will return non-zero if the system is in the process of shutting
> down.
>
> Unless I'm mistaken, this is just what I need.
>
> Thx
>
> H
>
>
> "Kerem Gümrükcü" wrote:
>
>> Hi Hugo,
>>
>> you dindt say what kind of application you are running
>> so i will tell you some ways this can be aquired/notfied:
>>
>> WM_QUERYENDSESSION //windowed applications
>> HandlerRoutine Callback Function //console based
>> RegisterServiceCtrlHandlerEx Function //service based
>>
>> Each of them will give you a "callback" whenever windows
>> is shutting down or a session changes. Whenever you get
>> a notification, then set some global flag indicating a shutdown
>> and check the flag before you make any calls,..
>>
>> You see there are many ways,... ;)
>>
>> regards
>>
>> Kerem
>>
>> --
>> -----------------------
>> Beste Grüsse / Best regards / Votre bien devoue
>> Kerem Gümrükcü
>> Latest Project: http://www.pro-it-education.de/software/deviceremover
>> Latest Open-Source Projects: http://entwicklung.junetz.de
>> -----------------------
>>
>> "Hugogleaves(a)hotmail.com>" <hugh<underbar> schrieb im Newsbeitrag
>> news:3F82C790-8545-4DC8-98A7-970E2193C9CB(a)microsoft.com...
>> > I'm a little surprised at something, it seems there is now way (no
>> > Win32
>> > function) to ask windows if a shutdown has been issued.
>> >
>> > I'd very much like ask the OS this question before I allow an app to
>> > call
>> > some other functions in a support library.
>> >
>> > The library updates mapped memory in all sorts of complicated ways.
>> >
>> > If a process is inside one of these update functions, partway through
>> > its
>> > work and the OS bluntly kills the app, then the mapped data will be
>> > flushed
>> > to disk OK but may be corrupt because the update function was
>> > interrupted.
>> >
>> > These functions execute very very rapidly, but there is always a
>> > "window"
>> > for failure.
>> >
>> > So I want to put code into these update functions that (in essence)
>> > does
>> > this:
>> >
>> > if (OsShutdownInProgress == FALSE)
>> > {
>> > do the fiddly update logic.
>> > }
>> > else
>> > return(OPERATION_PREVENTED_DUE_TO_OS_SHUTDOWN);
>> >
>> > This greatly reduces the window, so that in almost all cases we will
>> > get a
>> > clean failure in the update functions if user's app ignores shutdown
>> > and
>> > updates the mapped data via our API.
>> >
>> > But is there such a function?
>> >
>> > Is there any sort of info struct we can get from Windows, with a flag
>> > indicating that a shutdown has been started?
>> >
>> > Thanks
>> > H
>>
>> .
>>