1 ///////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/init.h
3 // Purpose:     wxWidgets initialization and finalization functions
4 // Author:      Vadim Zeitlin
5 // Modified by:
6 // Created:     29.06.2003
7 // RCS-ID:      $Id: init.h 61558 2009-07-30 10:14:36Z VS $
8 // Copyright:   (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence:     wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef _WX_INIT_H_
13 #define _WX_INIT_H_
14 
15 #include "wx/defs.h"
16 #include "wx/wxchar.h"
17 
18 // ----------------------------------------------------------------------------
19 // wxEntry helper functions which allow to have more fine grained control
20 // ----------------------------------------------------------------------------
21 
22 // do common initialization, return true if ok (in this case wxEntryCleanup
23 // must be called later), otherwise the program can't use wxWidgets at all
24 //
25 // this function also creates wxTheApp as a side effect, if IMPLEMENT_APP
26 // hadn't been used a dummy default application object is created
27 //
28 // note that the parameters may be modified, this is why we pass them by
29 // reference!
30 extern bool WXDLLIMPEXP_BASE wxEntryStart(int& argc, wxChar **argv);
31 
32 // free the resources allocated by the library in wxEntryStart() and shut it
33 // down (wxEntryStart() may be called again afterwards if necessary)
34 extern void WXDLLIMPEXP_BASE wxEntryCleanup();
35 
36 
37 // ----------------------------------------------------------------------------
38 // wxEntry: this function initializes the library, runs the main event loop
39 //          and cleans it up
40 // ----------------------------------------------------------------------------
41 
42 // note that other, platform-specific, overloads of wxEntry may exist as well
43 // but this one always exists under all platforms
44 //
45 // returns the program exit code
46 extern int WXDLLIMPEXP_BASE wxEntry(int& argc, wxChar **argv);
47 
48 // we overload wxEntry[Start]() to take "char **" pointers too
49 #if wxUSE_UNICODE
50 
51 extern bool WXDLLIMPEXP_BASE wxEntryStart(int& argc, char **argv);
52 extern int WXDLLIMPEXP_BASE wxEntry(int& argc, char **argv);
53 
54 #endif// wxUSE_UNICODE
55 
56 // ----------------------------------------------------------------------------
57 // Using the library without (explicit) application object: you may avoid using
58 // DECLARE_APP and IMPLEMENT_APP macros and call the functions below instead at
59 // the program startup and termination
60 // ----------------------------------------------------------------------------
61 
62 // initialize the library (may be called as many times as needed, but each
63 // call to wxInitialize() must be matched by wxUninitialize())
64 extern bool WXDLLIMPEXP_BASE wxInitialize(int argc = 0, wxChar **argv = NULL);
65 #if wxUSE_UNICODE && wxABI_VERSION >= 20811
66 extern bool WXDLLIMPEXP_BASE wxInitialize(int argc, char **argv);
67 #endif
68 
69 // clean up -- the library can't be used any more after the last call to
70 // wxUninitialize()
71 extern void WXDLLIMPEXP_BASE wxUninitialize();
72 
73 // create an object of this class on stack to initialize/cleanup the library
74 // automatically
75 class WXDLLIMPEXP_BASE wxInitializer
76 {
77 public:
78     // initialize the library
79     wxInitializer(int argc = 0, wxChar **argv = NULL)
80     {
81         m_ok = wxInitialize(argc, argv);
82     }
83 
84 #if wxUSE_UNICODE && wxABI_VERSION >= 20811
wxInitializer(int argc,char ** argv)85     wxInitializer(int argc, char **argv)
86     {
87         m_ok = wxInitialize(argc, argv);
88     }
89 #endif // wxUSE_UNICODE
90 
91     // has the initialization been successful? (explicit test)
IsOk()92     bool IsOk() const { return m_ok; }
93 
94     // has the initialization been successful? (implicit test)
95     operator bool() const { return m_ok; }
96 
97     // dtor only does clean up if we initialized the library properly
~wxInitializer()98     ~wxInitializer() { if ( m_ok ) wxUninitialize(); }
99 
100 private:
101     bool m_ok;
102 };
103 
104 #endif // _WX_INIT_H_
105 
106