Board index » cppbuilder » Exception: Exit application before Application->Run() in WinMain

Exception: Exit application before Application->Run() in WinMain

Hi there,
I have some code in WinMain as following

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
         Application->Initialize();
         Application->CreateForm(__classid(TRegForm),&RegModule);
         if ( something is true)
         {
            return 0;
         }
         Applicaiton->Run();

Quote
}

When "something" is true, running the application will throw an exception. Why?

4006DF7B C:\WINNT\System32\VCL50.BPL
400511D6 C:\WINNT\System32\VCL50.BPL
77E13EB0 C:\WINNT\system32\user32.dll
77E1591B C:\WINNT\system32\user32.dll
77E1595D C:\WINNT\system32\user32.dll
77F9FB83 ntdll.dll
400553D8 C:\WINNT\System32\VCL50.BPL
00406BD4 Forms::TForm::~TForm(this=:0105A7BC)

 

Re:Exception: Exit application before Application->Run() in WinMain


Have you tried calling abort() or terminate() instead of return 0?  That
might help.

Re:Exception: Exit application before Application->Run() in WinMain


By calling return 0 immediately, you're not allowing the VCL to clean up
after itself at all.  Call Application->Terminate() instead, which will
allow the VCL to do it's normal cleanup, and cause Application->Run() to
exit as soon as it starts, ie:

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
    Application->Initialize();
    Application->CreateForm(__classid(TRegForm),&RegModule);
    if ( something is true)
        Application->Terminate();
    else
        Application->Run();
    return 0;

Quote
}

Gambit

Quote
"robin" <ro...@mdi.ca> wrote in message news:3bd89e4a$1_1@dnews...
> When "something" is true, running the application will throw an exception.

Why?

Other Threads