]> git.saurik.com Git - wxWidgets.git/blob - src/msw/main.cpp
fixed unused variable warning
[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 // implementation: various entry points
56 // ============================================================================
57
58 // ----------------------------------------------------------------------------
59 // Windows-specific wxEntry
60 // ----------------------------------------------------------------------------
61
62 WXDLLEXPORT int wxEntry(HINSTANCE hInstance,
63 HINSTANCE WXUNUSED(hPrevInstance),
64 wxCmdLineArgType WXUNUSED(pCmdLine),
65 int nCmdShow)
66 {
67 // remember the parameters Windows gave us
68 wxSetInstance(hInstance);
69 wxApp::m_nCmdShow = nCmdShow;
70
71 // parse the command line: we can't use pCmdLine in Unicode build so it is
72 // simpler to never use it at all (this also results in a more correct
73 // argv[0])
74
75 // break the command line in words
76 wxArrayString args;
77 const wxChar *cmdLine = ::GetCommandLine();
78 if ( cmdLine )
79 {
80 args = wxCmdLineParser::ConvertStringToArgs(cmdLine);
81 }
82
83 int argc = args.GetCount();
84
85 // +1 here for the terminating NULL
86 wxChar **argv = new wxChar *[argc + 1];
87 for ( int i = 0; i < argc; i++ )
88 {
89 argv[i] = wxStrdup(args[i]);
90 }
91
92 // argv[] must be NULL-terminated
93 argv[argc] = NULL;
94
95 return wxEntry(argc, argv);
96 }
97
98 // May wish not to have a DllMain or WinMain, e.g. if we're programming
99 // a Netscape plugin or if we're writing a console application
100 #if !defined(NOMAIN)
101
102 extern "C"
103 {
104
105 // ----------------------------------------------------------------------------
106 // WinMain
107 // ----------------------------------------------------------------------------
108
109 // Note that WinMain is also defined in dummy.obj, which is linked to
110 // an application that is using the DLL version of wxWindows.
111
112 #if defined(_WINDLL)
113
114 // DLL entry point
115
116 BOOL WINAPI
117 DllMain(HANDLE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved))
118 {
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.
123 #ifndef WXMAKINGDLL
124 switch (fdwReason)
125 {
126 case DLL_PROCESS_ATTACH:
127 return wxEntry(hModule);
128
129 case DLL_PROCESS_DETACH:
130 wxEntryCleanup();
131 break;
132 }
133 #else
134 (void)hModule;
135 (void)fdwReason;
136 #endif // !WXMAKINGDLL
137
138 return TRUE;
139 }
140
141 #endif // _WINDLL
142
143 } // extern "C"
144
145 #endif // !NOMAIN
146
147 #endif // wxUSE_GUI
148
149 // ----------------------------------------------------------------------------
150 // global HINSTANCE
151 // ----------------------------------------------------------------------------
152
153 #if wxUSE_BASE
154
155 HINSTANCE wxhInstance = 0;
156
157 HINSTANCE wxGetInstance()
158 {
159 return wxhInstance;
160 }
161
162 void wxSetInstance(HINSTANCE hInst)
163 {
164 wxhInstance = hInst;
165 }
166
167 #endif // wxUSE_BASE
168