-1

I try to use wxWidgets in my C++ project.
As far as I know, for wxWidgets I need to use wxIMPLEMENT_APP(MyAPP ); instead of the main() function.
I don't understand how to write other functions to do other work before my wxWidgets graphics object is created.
In other words, I would like to understand how to get a result like this:

int main(int argc, char* argv[]) {
    configure_application_1();
    app_config app_cfg;
    app_configuration(app_cfg); 
    
    other_functions();

    ___create_wxWidgets________

}
Reza
  • 3,473
  • 4
  • 35
  • 54
SuperPuper
  • 51
  • 1
  • 1
  • 5
  • The question title seems unrelated to question description. – kiner_shah Jun 01 '22 at 12:09
  • Just create a global instance of something, and do work in its constructor function. Better leave the `main()` implementation to the wxWidgets framework. – πάντα ῥεῖ Jun 01 '22 at 12:11
  • Highly related, if not a duplicate: https://stackoverflow.com/questions/10897552/call-a-function-before-main – πάντα ῥεῖ Jun 01 '22 at 12:16
  • @SuperPuper, first - there is no such thing as `create wxWidgets`. Sercond - did you try to buyild and run `minimal` sample and look at its code? Are you trying to learn C++? – Igor Jun 01 '22 at 13:53

2 Answers2

3

According to the official doc:

A wxWidgets application does not have a main procedure; the equivalent is the wxApp::OnInit member defined for a class derived from wxApp.

So put your code in wxApp::OnInit function.

Reza
  • 3,473
  • 4
  • 35
  • 54
2

The main(), or WinMain() (or other entry points that used to exist, but don't any more because the corresponding platforms have gone extinct), is part of wxIMPLEMENT_APP() macro expansion. If you don't want it to define your entry point, you can use wxIMPLEMENT_APP_NO_MAIN(), but then you're responsible for initializing the library yourself.

However typically you would just leave it be and put your initialization code in your overridden MyApp::OnInit(), where MyApp is your class inheriting from wxApp.

VZ.
  • 21,740
  • 3
  • 39
  • 42