]> git.saurik.com Git - wxWidgets.git/blob - src/msw/main.cpp
removing rtti special functions
[wxWidgets.git] / src / msw / main.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/main.cpp
3 // Purpose: WinMain/DllMain
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #include "wx/event.h"
32 #include "wx/app.h"
33 #include "wx/cmdline.h"
34
35 #include "wx/msw/private.h"
36
37 // Don't implement WinMain if we're building an MFC/wxWindows hybrid app.
38 #if wxUSE_MFC && !defined(NOMAIN)
39 #define NOMAIN 1
40 #endif
41
42 #ifdef __BORLANDC__
43 // BC++ has to be special: its run-time expects the DLL entry point to be
44 // named DllEntryPoint instead of the (more) standard DllMain
45 #define DllMain DllEntryPoint
46 #endif
47
48 #if defined(__WXMICROWIN__)
49 #define HINSTANCE HANDLE
50 #endif
51
52 #if wxUSE_GUI
53
54 // ----------------------------------------------------------------------------
55 // function prototypes
56 // ----------------------------------------------------------------------------
57
58 static wxChar **ConvertToStandardCommandArgs(const wxChar *p, int& argc);
59
60 // ============================================================================
61 // implementation: various entry points
62 // ============================================================================
63
64 // ----------------------------------------------------------------------------
65 // Windows-specific wxEntry
66 // ----------------------------------------------------------------------------
67
68 WXDLLEXPORT int wxEntry(HINSTANCE hInstance,
69 HINSTANCE WXUNUSED(hPrevInstance),
70 char *pCmdLine,
71 int nCmdShow)
72 {
73 // remember the parameters Windows gave us
74 wxSetInstance(hInstance);
75 wxApp::m_nCmdShow = nCmdShow;
76
77 // parse the command line
78 int argc;
79 wxChar **argv = ConvertToStandardCommandArgs(wxConvertMB2WX(pCmdLine), argc);
80
81 return wxEntry(argc, argv);
82 }
83
84 // May wish not to have a DllMain or WinMain, e.g. if we're programming
85 // a Netscape plugin or if we're writing a console application
86 #if !defined(NOMAIN)
87
88 extern "C"
89 {
90
91 // ----------------------------------------------------------------------------
92 // WinMain
93 // ----------------------------------------------------------------------------
94
95 // Note that WinMain is also defined in dummy.obj, which is linked to
96 // an application that is using the DLL version of wxWindows.
97
98 #if defined(_WINDLL)
99
100 // DLL entry point
101
102 BOOL WINAPI
103 DllMain(HANDLE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved))
104 {
105 // Only call wxEntry if the application itself is part of the DLL.
106 // If only the wxWindows library is in the DLL, then the
107 // initialisation will be called when the application implicitly
108 // calls WinMain.
109 #ifndef WXMAKINGDLL
110 switch (fdwReason)
111 {
112 case DLL_PROCESS_ATTACH:
113 return wxEntry(hModule);
114
115 case DLL_PROCESS_DETACH:
116 wxEntryCleanup();
117 break;
118 }
119 #else
120 (void)hModule;
121 (void)fdwReason;
122 #endif // !WXMAKINGDLL
123
124 return TRUE;
125 }
126
127 #endif // _WINDLL
128
129 } // extern "C"
130
131 #endif // !NOMAIN
132
133 // ---------------------------------------------------------------------------
134 // Convert Windows to argc, argv style
135 // ---------------------------------------------------------------------------
136
137 wxChar **ConvertToStandardCommandArgs(const wxChar *p, int& argc)
138 {
139 // break the command line in words
140 wxArrayString args;
141 if ( p )
142 {
143 args = wxCmdLineParser::ConvertStringToArgs(p);
144 }
145
146 // +1 here for the program name
147 argc = args.GetCount() + 1;
148
149 // and +1 here for the terminating NULL
150 wxChar **argv = new wxChar *[argc + 1];
151
152 // as we use wxStrdup below we must allocate the first argument using
153 // malloc(), not new[], as well
154 argv[0] = (wxChar *)malloc(MAX_PATH * sizeof(wxChar));
155 ::GetModuleFileName(wxhInstance, argv[0], MAX_PATH);
156
157 // copy all the other arguments to wxApp::argv[]
158 for ( int i = 1; i < argc; i++ )
159 {
160 argv[i] = wxStrdup(args[i - 1]);
161 }
162
163 // argv[] must be NULL-terminated
164 argv[argc] = NULL;
165
166 return argv;
167 }
168
169 #endif // wxUSE_GUI
170
171 // ----------------------------------------------------------------------------
172 // global HINSTANCE
173 // ----------------------------------------------------------------------------
174
175 #if wxUSE_BASE
176
177 HINSTANCE wxhInstance = 0;
178
179 HINSTANCE wxGetInstance()
180 {
181 return wxhInstance;
182 }
183
184 void wxSetInstance(HINSTANCE hInst)
185 {
186 wxhInstance = hInst;
187 }
188
189 #endif // wxUSE_BASE
190