Solved

Shutting down application on pipes message

Posted on 2009-05-05
4
601 Views
Last Modified: 2012-05-06
Hi, I'm trying to use rlibby's TPipeServer/Client components for interprocess communication. In this case I want to shut down the server application upon receiving the message 'QUIT'. This causes problems because the pipeserver component does not seem to handle it very well when it is being destroyed while handling a message. It causes an access violation in ntdll read of address 00000010.

Does anyone have a solution on how to do this, maybe by changing the code on the message recieving end, or by modifying the pipe component?

Also see the related question on how to get the pipes components working.

Im using Delphi 2009 v12.0.3210.17555 and the pipes components of 10.20.2008.
Procedure TForm1.PipeServer1PipeMessage(Sender: TObject; Pipe: HPIPE; Stream: TStream);
var S: AnsiString;
begin
  SetLength(S, Stream.Size);
  Stream.Read(S[1], Length(S));
  if (S = 'QUIT') then
  begin
    PipeServer1.Active := false;
    Close; // causes access violation in pipeserver component!
  end;
end;

Open in new window

0
Comment
Question by:mrdnote
  • 2
4 Comments
 
LVL 37

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 100 total points
ID: 24303296
give it time to close down, send a close message instead ...

if (S = 'QUIT') then
begin
  PipeServer1.Active := false;
  PostMessage(Handle, WM_CLOSE, 0, 0);
end;
0
 

Author Comment

by:mrdnote
ID: 24303349
Thanx Geert. Somehow setting Active to False does something to the message queue, causing it not to process the WM_CLOSE message. If I remove the PipeServer1.Active := false line, the WM_CLOSE is propagated and the form closes, however the access violation remains :(
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24303390
what does the stack trace tell you ?
press - Ctrl-F3 to see what originated a procedure.

That could tell you what the cause of the violation is.
Check all procedures in this list to see if they don't access a component which has been freed allready.
You may have to press F7 once, to get a decent stack trace.
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 150 total points
ID: 24304418

Don't touch the active state in the event handler for the pipe server, because it will cause the message queue to flush when the DoShutdown procedure gets called. Just PostMessage the WM_CLOSE to your handle, and then in the FormClose set the Active state to false.

Regards,
Russell
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 68
add combobox item based on numbers 9 154
Process Javascript errors with Delphi TWebBrowser 1 178
Magic Software info 18 139
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question