]> git.saurik.com Git - wxWidgets.git/blame - src/msw/main.cpp
removing unreached code (overriden)
[wxWidgets.git] / src / msw / main.cpp
CommitLineData
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
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 37// Don't implement WinMain if we're building an MFC/wxWindows hybrid app.
4cd513ab 38#if wxUSE_MFC && !defined(NOMAIN)
e2478fde 39 #define NOMAIN 1
4cd513ab
JS
40#endif
41
e2478fde
VZ
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
beed393c 51
94826170
VZ
52#if wxUSE_GUI
53
b568d04f 54// ----------------------------------------------------------------------------
e2478fde 55// function prototypes
b568d04f
VZ
56// ----------------------------------------------------------------------------
57
94826170
VZ
58static wxChar **ConvertToStandardCommandArgs(const wxChar *p, int& argc);
59
b568d04f 60// ============================================================================
e2478fde 61// implementation: various entry points
b568d04f
VZ
62// ============================================================================
63
94826170
VZ
64// ----------------------------------------------------------------------------
65// Windows-specific wxEntry
66// ----------------------------------------------------------------------------
67
b5fe6924
VS
68WXDLLEXPORT int wxEntry(HINSTANCE hInstance,
69 HINSTANCE WXUNUSED(hPrevInstance),
70 char *pCmdLine,
71 int nCmdShow)
94826170
VZ
72{
73 // remember the parameters Windows gave us
13bdd545 74 wxSetInstance(hInstance);
94826170
VZ
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
2bda0e17 84// May wish not to have a DllMain or WinMain, e.g. if we're programming
b568d04f 85// a Netscape plugin or if we're writing a console application
94826170 86#if !defined(NOMAIN)
2bda0e17 87
e2478fde
VZ
88extern "C"
89{
2bda0e17 90
e2478fde 91// ----------------------------------------------------------------------------
2bda0e17 92// WinMain
e2478fde
VZ
93// ----------------------------------------------------------------------------
94
2bda0e17
KB
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
ac9a3c61 98#if defined(_WINDLL)
2bda0e17
KB
99
100// DLL entry point
101
e2478fde
VZ
102BOOL WINAPI
103DllMain(HANDLE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved))
2bda0e17 104{
e2478fde
VZ
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.
beed393c 109#ifndef WXMAKINGDLL
2bda0e17 110 switch (fdwReason)
b568d04f
VZ
111 {
112 case DLL_PROCESS_ATTACH:
13bdd545 113 return wxEntry(hModule);
2bda0e17 114
b568d04f 115 case DLL_PROCESS_DETACH:
94826170
VZ
116 wxEntryCleanup();
117 break;
b568d04f 118 }
33ac7e6f
KB
119#else
120 (void)hModule;
121 (void)fdwReason;
beed393c 122#endif // !WXMAKINGDLL
e2478fde 123
b568d04f 124 return TRUE;
2bda0e17
KB
125}
126
ac9a3c61 127#endif // _WINDLL
e2478fde
VZ
128
129} // extern "C"
2bda0e17 130
b568d04f
VZ
131#endif // !NOMAIN
132
94826170
VZ
133// ---------------------------------------------------------------------------
134// Convert Windows to argc, argv style
135// ---------------------------------------------------------------------------
136
137wxChar **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
f252f8c3
VZ
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));
94826170
VZ
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
b568d04f 171// ----------------------------------------------------------------------------
e2478fde 172// global HINSTANCE
b568d04f
VZ
173// ----------------------------------------------------------------------------
174
ec67cff1 175#if wxUSE_BASE
e2478fde
VZ
176
177HINSTANCE wxhInstance = 0;
178
b568d04f
VZ
179HINSTANCE wxGetInstance()
180{
181 return wxhInstance;
182}
183
184void wxSetInstance(HINSTANCE hInst)
185{
186 wxhInstance = hInst;
187}
2bda0e17 188
ec67cff1 189#endif // wxUSE_BASE
e2478fde 190