Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 May : WM_QUERYENDSESSION and WM_ENDSESSION problems

www.cryer.info
Managed Newsgroup Archive

WM_QUERYENDSESSION and WM_ENDSESSION problems

Subject:WM_QUERYENDSESSION and WM_ENDSESSION problems
Posted by:"Matt Hardiman" (newsgroupr@-remove-me-matti.co.uk)
Date:Thu, 4 May 2006 12:45:15 +0100

Hi, I'm using Delphi 7 (PRO) and have a pretty large audio editing
application which is primarily a SOAP client and Active-X host.

The problem I have is that - with my application running - if the user
attempts to logoff or shutdown / restart windows, Windows does not shutdown
/ restart etc. My application is not becoming unresponsive and can be closed
manually as normal. If my application is closed in advance of the logoff /
restart etc then all is fine.

I started looking at the WM_QUERYENDSESSION and  WM_ENDSESSION messages and
found that the forms on my application are receiving the WM_ENDSESSION
message but with the fEndSession flag set to false - which implies that
something (and process of elimination means it's my application) is replying
to the QUERYENDSESSION and telling windows not to shutdown / restart etc...

The problem is that I can't catch the QUERYENDSESSION message on any of my
forms - I've written message handler procedures but they never get called. A
little googling implies that there is something else in my application which
is catching the QUERYENDSESSION message and responding (or rather setting
the Msg.Result to 0) with do not shut down.

I'm using a whole host of third party stuff including
* Async PRO
* Delphi Jedi VCL - masked edit boxes / tip of day
* Swiftsoft MM components
* A third party Active-X audio Editor component
* Delphi SOAP

So my problem is that I'm stumped at how to track the offending bit of code
down - it may well be my own code and not the third party code but I just
can't find it. The problem is that since the bug is when you restart your
windows session, the Delphi debugger shuts down, so does winsight and
anything else I try to use to see what's going on. I'm using trial and error
and log files to try and track it but have got stuck. Anyone any kind
helpful thoughts about a decent strategy to try and find the problem - I
could well be barking up the wrong tree with the QUERYENDSESSION stuff, so
any thoughts gratefully received

many thanks

matt


sample log:
========
04/05/2006 12:24:31 - TForm1main.GetAttachService called
04/05/2006 12:24:32 - TForm1main.LockGUI stuff called (unlock)
04/05/2006 12:24:32 - TForm1main.WMAfterShow about to get MOTD
04/05/2006 12:24:32 - TForm1main.WMAfterShow finished

[windows restart called here]

04/05/2006 12:24:41 - TForm1main.WMEndSession
04/05/2006 12:24:41 - TForm1main.WMEndSession fEndSession=false
04/05/2006 12:24:41 - TForm16Recorder.WMEndSession
04/05/2006 12:24:41 - TForm12editor.WMEndSession
04/05/2006 12:24:41 - TForm16Recorder.form destroy
04/05/2006 12:24:41 - TForm12editor.FormDestroy called
04/05/2006 12:24:41 - TForm1main.FormDestroy called
04/05/2006 12:24:41 - TForm1main.FormDestroy about to release interest in
files
04/05/2006 12:24:41 - TForm1main.FormDestroy about release HTML help
04/05/2006 12:24:42 - TForm1main.FormDestroy about to close down this log!


sample code
=========

type
  TForm1main = class(TForm)
     ...
  private
    procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message
WM_QUERYENDSESSION;
    procedure WMEndSession(var Msg : TWMQueryEndSession); message
WM_ENDSESSION ;
  end;


procedure TForm1main .WMQueryEndSession(var Msg: TWMQueryEndSession);
var
  fEndSession : boolean;
begin
  fEndSession := boolean( TMessage(Msg).wParam);     // end-session flag
  GeneralLogMsg(TForm1main .WMQueryEndSession fEndSession=' +
booltostring(fEndSession));
  GeneralLogMsg(TForm1main .WMQueryEndSession');
  Msg.Result := 1;
  bShutDown  := true;
end;


procedure TForm1main .WMEndSession(var Msg : TWMQueryEndSession);
var
  fEndSession : boolean;
begin
  GeneralLogMsg(TForm1main .WMEndSession');
  Msg.Result := 1;
  try
    fEndSession := boolean( TMessage(Msg).wParam);     // end-session flag
    GeneralLogMsg(TForm1main .WMEndSession fEndSession=' +
booltostring(fEndSession));
  except
    on e: exception do
      begin
        GeneralLogMsg(TForm1main .WMEndSession raised ' + e.Message);
      end;
  end;
end;

Info

Glossary

Replies:

www.cryer.info
Managed Newsgroup Archive