Some unnecessary wxUSE_MFC occurences removed following Vadim's experience (see wx...
[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 #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
46
47 #if wxUSE_GUI
48
49 // ============================================================================
50 // implementation: various entry points
51 // ============================================================================
52
53 // ----------------------------------------------------------------------------
54 // Windows-specific wxEntry
55 // ----------------------------------------------------------------------------
56
57 WXDLLEXPORT int wxEntry(HINSTANCE hInstance,
58 HINSTANCE WXUNUSED(hPrevInstance),
59 wxCmdLineArgType WXUNUSED(pCmdLine),
60 int nCmdShow)
61 {
62 // remember the parameters Windows gave us
63 wxSetInstance(hInstance);
64 wxApp::m_nCmdShow = nCmdShow;
65
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;
89
90 return wxEntry(argc, argv);
91 }
92
93 // May wish not to have a DllMain or WinMain, e.g. if we're programming
94 // a Netscape plugin or if we're writing a console application
95 #if !defined(NOMAIN)
96
97 extern "C"
98 {
99
100 // ----------------------------------------------------------------------------
101 // WinMain
102 // ----------------------------------------------------------------------------
103
104 // Note that WinMain is also defined in dummy.obj, which is linked to
105 // an application that is using the DLL version of wxWidgets.
106
107 #if defined(_WINDLL)
108
109 // DLL entry point
110
111 BOOL WINAPI
112 DllMain(HANDLE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved))
113 {
114 // Only call wxEntry if the application itself is part of the DLL.
115 // If only the wxWidgets library is in the DLL, then the
116 // initialisation will be called when the application implicitly
117 // calls WinMain.
118 #ifndef WXMAKINGDLL
119 switch (fdwReason)
120 {
121 case DLL_PROCESS_ATTACH:
122 return wxEntry(hModule);
123
124 case DLL_PROCESS_DETACH:
125 wxEntryCleanup();
126 break;
127 }
128 #else
129 (void)hModule;
130 (void)fdwReason;
131 #endif // !WXMAKINGDLL
132
133 return TRUE;
134 }
135
136 #endif // _WINDLL
137
138 } // extern "C"
139
140 #endif // !NOMAIN
141
142 #endif // wxUSE_GUI
143
144 // ----------------------------------------------------------------------------
145 // global HINSTANCE
146 // ----------------------------------------------------------------------------
147
148 #if wxUSE_BASE
149
150 HINSTANCE wxhInstance = 0;
151
152 HINSTANCE wxGetInstance()
153 {
154 return wxhInstance;
155 }
156
157 void wxSetInstance(HINSTANCE hInst)
158 {
159 wxhInstance = hInst;
160 }
161
162 #endif // wxUSE_BASE
163