Page 1 of 1

Where is MAIN ?

Posted: Tue Apr 26, 2005 2:13 pm
by johnb
I have completed a wxform called Siotest. It complies and runs perfectly.
The question now is, Where is the 'MAIN' proceedure (new to c++) and
where do I enter my code.

I think this might be the equivalent to 'MAIN'

In 'Siotestapp.cpp'

bool SiotestFrmApp::OnInit()
{
SiotestFrm "myFrame = new SiotestFrm(NULL);
SetTopWindow(myFrame);
myFrame->Show(TRUE);
return TRUE;
}

Where do I enter my code for my Sio Test application ?

Re: Where is MAIN ?

Posted: Tue Apr 26, 2005 2:24 pm
by upCASE
Hi!
johnb wrote: The question now is, Where is the 'MAIN' proceedure (new to c++) and
where do I enter my code.

I think this might be the equivalent to 'MAIN'

In 'Siotestapp.cpp'

bool SiotestFrmApp::OnInit()
{
SiotestFrm "myFrame = new SiotestFrm(NULL);
SetTopWindow(myFrame);
myFrame->Show(TRUE);
return TRUE;
}
Where do I enter my code for my Sio Test application ?
You're right, OnInit() is the main entrance to your application as it starts the main event loop.
The "main" function (or "WinMain" on Windows) gets implemented automatically by using the IMPLEMENT_APP() macro. This macro expands to the correct "main" form for your platform.

Where you enter your code is up to you... Most likely you create a frame like "myFrame" and add your code and event handlers there.
Check out NinjaNLs tutorial hosted on my site http://www.upcase.de/wxDevCpp_tutorial/ ... nimal.html

Re: Where is MAIN ?

Posted: Fri Jun 10, 2022 10:48 am
by rocvan
upCASE wrote: Tue Apr 26, 2005 2:24 pm You're right, OnInit() is the main entrance to your application as it starts the main event loop.
The "main" function (or "WinMain" on Windows) gets implemented automatically by using the IMPLEMENT_APP() macro. This macro expands to the correct "main" form for your platform.

Where you enter your code is up to you... Most likely you create a frame like "myFrame" and add your code and event handlers there.
Check out NinjaNLs tutorial hosted on my site http://www.upcase.de/wxDevCpp_tutorial/ ... nimal.html
Hi, I read and studied this very old post.

I met a problem, my main(...) has some setup in between the myFrame.

The simple flow as follow:

main() {
//initial some files handle
//read, update data to file


//show the ui
//myApp, myFrame process


//need to get the response from UI
//write data to file
//close the file handle

}

There is a OnInit and OnExit in myApp.

The main problem is the initialization and write files in between the UI display. It is difficult to split such initialization process in OnInit, then update and close files handle in OnExit.

Is there any method to keep the main() like structure?

Thanks

Re: Where is MAIN ?

Posted: Fri Jun 10, 2022 10:58 am
by PB
Please do not revive ancient threads.

If you prefer to keep your main() / WinMain(), you can use one of wxEntry*() functions or wxInitializer.

But I think you should have a really good reason to break the usual pattern.

Re: Where is MAIN ?

Posted: Wed Jun 15, 2022 9:29 am
by rocvan
PB wrote: Fri Jun 10, 2022 10:58 am Please do not revive ancient threads.

If you prefer to keep your main() / WinMain(), you can use one of wxEntry*() functions or wxInitializer.

But I think you should have a really good reason to break the usual pattern.
Many thanks.

I have tried the wxEntry(), the UI resolution is a bit lower, not sure the reason.

Felt that if open a new topic, the question will be duplicated.

Re: Where is MAIN ?

Posted: Thu Jun 16, 2022 6:31 pm
by ONEEYEMAN
Hi,
First of all - there is no duplication of the thread with the question, only duplication of the code. ;-)
Second - it is generally very good idea to close file handle(s) after you are done and not keep them open until the application is closed.

Essentially you application will keep the file exclusively open just for itself and nobody else will be able to do anything with them - not even you on another thread/Terminal. You don't want to do that.
And what happen if you accidentally forget to close one of the handles? You will have to reboot and spend some time researching why you can't run the progrm second time...

Now in regards to keeping the main() - why?
Is your application a GUI or console based? Is it a C++ or C based?
Are you yourself coming from the C background?

What is it that you can't do in the OnInit() that will absolutely have to happen in a matter of milliseconds after the user starts an application and it absolutely can't happen in 1 second? Please be as detailed as possible here.

Thank you.

Re: Where is MAIN ?

Posted: Mon Jun 20, 2022 9:27 am
by rocvan
ONEEYEMAN wrote: Thu Jun 16, 2022 6:31 pm Second - it is generally very good idea to close file handle(s) after you are done and not keep them open until the application is closed.
Hello, thanks a lot.
The existing code is redirect the stdio to file, so it open the file handle until close. The main purpose is to trace any exception in other library.
That's a good suggestion to close other file handle, will try it.
ONEEYEMAN wrote: Thu Jun 16, 2022 6:31 pm Now in regards to keeping the main() - why?
Is your application a GUI or console based? Is it a C++ or C based?
Are you yourself coming from the C background?
Yes, myself coming from C background.

The original application is console based, will parse the argc, argv then pass the value into other library (black box). It is c++ based code with very minimal c code internal (e.g. c like pointer casting). When shift to GUI based, some design need to keep, that's why open the file handle until terminate.
ONEEYEMAN wrote: Thu Jun 16, 2022 6:31 pm What is it that you can't do in the OnInit() that will absolutely have to happen in a matter of milliseconds after the user starts an application and it absolutely can't happen in 1 second? Please be as detailed as possible here.
Haven't realize this, the original design redirect the stdio to file and then will copy that file to another file after user quit the UI. Thinking how to optimize the program flow.

Thanks again.