Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to terminate a application immediately

1 view
Skip to first unread message

HuangC

unread,
Jul 1, 2003, 9:42:15 PM7/1/03
to
hi all,

I want to terminate a application immediately
when the initialize some object failed in the
construct funtion.I try to use
Application->Terminate(); return;
but the application continue creating other forms however.

any hint? TIA

HuangC


Vladimir Afanasyev

unread,
Jul 2, 2003, 8:21:55 AM7/2/03
to

Hi,

Do you tried ExitProcess Win32 API function?
Vladimir.

Rodolfo Frino

unread,
Jul 2, 2003, 9:30:36 AM7/2/03
to
Use either ExitProcess() or TerminateProcess() Win32 API's. However, bear in
mind that
ExitProcess is the preferred method of terminating a process since it calls
the entry-point function
of all attached DLLs with a value indicating that the process is detaching
from the DLL.

"Computers don't die, they password away"
Rodolfo Frino


"HuangC" <Hua...@motic.com.cn> wrote in message
news:3f0238c6$1...@newsgroups.borland.com...

Remy Lebeau (TeamB)

unread,
Jul 4, 2003, 8:34:00 PM7/4/03
to

"HuangC" <Hua...@motic.com.cn> wrote in message
news:3f0238c6$1...@newsgroups.borland.com...

> I want to terminate a application immediately


> when the initialize some object failed in the
> construct funtion.I try to use
> Application->Terminate(); return;
> but the application continue creating other
> forms however.

Application->Terminate() simply posts a WM_QUIT message to the message
queue, which will not be processed until later on when the queue begins
being pumped for messages.

If you are doing your initialization in the MainForm's constructor, then
simply throw an exception to indicate a failure. An exception is the only
way to return a failure from a constructor. Throwing an exception from the
MainForm will prevent the other forms from being created.

The alternative is to alter the project's WinMain() function directly, to do
your initializations before the first form is ever created. Then you can
bort your program more gracefully when needed.


Gambit


0 new messages