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