Terminating an App started via DLL.

Hi all,

I have an application where I can hook special functions etc. via a
DLL call.  ie: Source code to the app isn't available but I can hook
in a DLL that has a specific format and structure.  Parameters are
passed via one of the arguments to the DLL.  Inside the DLL is a case
statement and one of the cases is a Startup case.  This is all done
with generic C for Windows; not C++.

OK.  When I receive the startup case I want to launch a window that I
created in Delphi.  When the main application stops I get another
message to the DLL that says that things are stopping so clean up.

So far so simple and I made test program.  What I've done is created a
project that just calls two functions in a DLL.  It has a window with
the standard exit button that calls close and also two other buttons
that call the two DLL functions.

The second project is the DLL that exports those two functions.  One
of the two functions lauches the stock internet Chat sample program.

procedure InitForm(MainHandle : HWND);
begin
  Application.Initialize;
  Application.Handle := MainHandle;
  Application.CreateForm(TChatForm, ChatForm);
  Application.Run;
end;

The second function terminates the Chat program the same way the Chat
does when its exit button is pressed.

procedure TerminateForm;
begin
  ChatForm.ServerSocket.Close;
  ChatForm.ClientSocket.Close;
  ChatForm.Close;
end;

Now here is where it gets complicated.  Because the Application.Run
method doesn't return until the Chat application closes the button
method in the test program never finishes.  Then when the Stop button
is pressed in the test program nothing happens but when I press the
stop button again both the application and the Chat Form close.

Even when I create a far simpler application than chat and try the
same thing I still have problems.  First step I think,  is to somehow
launch the chat form and return immediately.  In C under Unix I'd
spawn a new task and continue but this Delphi stuff is different.

Also,  I'd like the Chat Form to remain within the boundry of the
Parent window and get minimized when the parent is minimized.  Do I
need to create all this as MDI?

Any suggestions would be appreciated.

Thanks,

John

Automation Artisans Inc. is a company founded to provide unique, advanced technology software and hardware solutions to the manufacturing industry so that our customers can produce customized products at mass production costs.

Automation Artisans Inc.,   PO Box 20002 Sidney, BC CANADA V8L 5C9
Ph. 1-250-544-4950  Fax 1-250-544-4954