Where is MAIN ?

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
johnb
Earned a small fee
Earned a small fee
Posts: 12
Joined: Fri Apr 22, 2005 3:28 pm

Where is MAIN ?

Post 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 ?
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Re: Where is MAIN ?

Post 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
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
rocvan
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sat May 14, 2022 6:42 am

Re: Where is MAIN ?

Post 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
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4182
Joined: Sun Jan 03, 2010 5:45 pm

Re: Where is MAIN ?

Post 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.
rocvan
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sat May 14, 2022 6:42 am

Re: Where is MAIN ?

Post 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.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Where is MAIN ?

Post 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.
rocvan
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sat May 14, 2022 6:42 am

Re: Where is MAIN ?

Post 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.
Post Reply