]>
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 | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
b568d04f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
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" |
94826170 | 33 | #include "wx/cmdline.h" |
b568d04f VZ |
34 | |
35 | #include "wx/msw/private.h" | |
36 | ||
e2478fde VZ |
37 | #ifdef __BORLANDC__ |
38 | // BC++ has to be special: its run-time expects the DLL entry point to be | |
39 | // named DllEntryPoint instead of the (more) standard DllMain | |
40 | #define DllMain DllEntryPoint | |
41 | #endif | |
42 | ||
43 | #if defined(__WXMICROWIN__) | |
44 | #define HINSTANCE HANDLE | |
45 | #endif | |
beed393c | 46 | |
94826170 VZ |
47 | #if wxUSE_GUI |
48 | ||
b568d04f | 49 | // ============================================================================ |
e2478fde | 50 | // implementation: various entry points |
b568d04f VZ |
51 | // ============================================================================ |
52 | ||
94826170 VZ |
53 | // ---------------------------------------------------------------------------- |
54 | // Windows-specific wxEntry | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
b5fe6924 VS |
57 | WXDLLEXPORT int wxEntry(HINSTANCE hInstance, |
58 | HINSTANCE WXUNUSED(hPrevInstance), | |
7c8c7cc2 | 59 | wxCmdLineArgType WXUNUSED(pCmdLine), |
b5fe6924 | 60 | int nCmdShow) |
94826170 VZ |
61 | { |
62 | // remember the parameters Windows gave us | |
13bdd545 | 63 | wxSetInstance(hInstance); |
94826170 VZ |
64 | wxApp::m_nCmdShow = nCmdShow; |
65 | ||
b2b1371c VZ |
66 | // parse the command line: we can't use pCmdLine in Unicode build so it is |
67 | // simpler to never use it at all (this also results in a more correct | |
68 | // argv[0]) | |
69 | ||
70 | // break the command line in words | |
71 | wxArrayString args; | |
72 | const wxChar *cmdLine = ::GetCommandLine(); | |
73 | if ( cmdLine ) | |
74 | { | |
75 | args = wxCmdLineParser::ConvertStringToArgs(cmdLine); | |
76 | } | |
77 | ||
78 | int argc = args.GetCount(); | |
79 | ||
80 | // +1 here for the terminating NULL | |
81 | wxChar **argv = new wxChar *[argc + 1]; | |
82 | for ( int i = 0; i < argc; i++ ) | |
83 | { | |
84 | argv[i] = wxStrdup(args[i]); | |
85 | } | |
86 | ||
87 | // argv[] must be NULL-terminated | |
88 | argv[argc] = NULL; | |
94826170 VZ |
89 | |
90 | return wxEntry(argc, argv); | |
91 | } | |
92 | ||
2bda0e17 | 93 | // May wish not to have a DllMain or WinMain, e.g. if we're programming |
b568d04f | 94 | // a Netscape plugin or if we're writing a console application |
94826170 | 95 | #if !defined(NOMAIN) |
2bda0e17 | 96 | |
e2478fde VZ |
97 | extern "C" |
98 | { | |
2bda0e17 | 99 | |
e2478fde | 100 | // ---------------------------------------------------------------------------- |
2bda0e17 | 101 | // WinMain |
e2478fde VZ |
102 | // ---------------------------------------------------------------------------- |
103 | ||
2bda0e17 | 104 | // Note that WinMain is also defined in dummy.obj, which is linked to |
77ffb593 | 105 | // an application that is using the DLL version of wxWidgets. |
2bda0e17 | 106 | |
ac9a3c61 | 107 | #if defined(_WINDLL) |
2bda0e17 KB |
108 | |
109 | // DLL entry point | |
110 | ||
e2478fde VZ |
111 | BOOL WINAPI |
112 | DllMain(HANDLE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved)) | |
2bda0e17 | 113 | { |
e2478fde | 114 | // Only call wxEntry if the application itself is part of the DLL. |
77ffb593 | 115 | // If only the wxWidgets library is in the DLL, then the |
e2478fde VZ |
116 | // initialisation will be called when the application implicitly |
117 | // calls WinMain. | |
beed393c | 118 | #ifndef WXMAKINGDLL |
2bda0e17 | 119 | switch (fdwReason) |
b568d04f VZ |
120 | { |
121 | case DLL_PROCESS_ATTACH: | |
13bdd545 | 122 | return wxEntry(hModule); |
2bda0e17 | 123 | |
b568d04f | 124 | case DLL_PROCESS_DETACH: |
94826170 VZ |
125 | wxEntryCleanup(); |
126 | break; | |
b568d04f | 127 | } |
33ac7e6f | 128 | #else |
598ddd96 WS |
129 | (void)hModule; |
130 | (void)fdwReason; | |
beed393c | 131 | #endif // !WXMAKINGDLL |
e2478fde | 132 | |
b568d04f | 133 | return TRUE; |
2bda0e17 KB |
134 | } |
135 | ||
ac9a3c61 | 136 | #endif // _WINDLL |
e2478fde VZ |
137 | |
138 | } // extern "C" | |
2bda0e17 | 139 | |
b568d04f VZ |
140 | #endif // !NOMAIN |
141 | ||
94826170 VZ |
142 | #endif // wxUSE_GUI |
143 | ||
b568d04f | 144 | // ---------------------------------------------------------------------------- |
e2478fde | 145 | // global HINSTANCE |
b568d04f VZ |
146 | // ---------------------------------------------------------------------------- |
147 | ||
ec67cff1 | 148 | #if wxUSE_BASE |
e2478fde VZ |
149 | |
150 | HINSTANCE wxhInstance = 0; | |
151 | ||
b568d04f VZ |
152 | HINSTANCE wxGetInstance() |
153 | { | |
154 | return wxhInstance; | |
155 | } | |
156 | ||
157 | void wxSetInstance(HINSTANCE hInst) | |
158 | { | |
159 | wxhInstance = hInst; | |
160 | } | |
2bda0e17 | 161 | |
ec67cff1 | 162 | #endif // wxUSE_BASE |
e2478fde | 163 |