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