]> git.saurik.com Git - wxWidgets.git/blame - src/msw/main.cpp
removed wxFunction
[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
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"
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
e2478fde
VZ
58// from src/msw/app.cpp
59extern void WXDLLEXPORT wxEntryCleanup();
b568d04f 60
94826170
VZ
61static wxChar **ConvertToStandardCommandArgs(const wxChar *p, int& argc);
62
b568d04f 63// ============================================================================
e2478fde 64// implementation: various entry points
b568d04f
VZ
65// ============================================================================
66
94826170
VZ
67// ----------------------------------------------------------------------------
68// Windows-specific wxEntry
69// ----------------------------------------------------------------------------
70
b5fe6924
VS
71WXDLLEXPORT int wxEntry(HINSTANCE hInstance,
72 HINSTANCE WXUNUSED(hPrevInstance),
73 char *pCmdLine,
74 int nCmdShow)
94826170
VZ
75{
76 // remember the parameters Windows gave us
13bdd545 77 wxSetInstance(hInstance);
94826170
VZ
78 wxApp::m_nCmdShow = nCmdShow;
79
80 // parse the command line
81 int argc;
82 wxChar **argv = ConvertToStandardCommandArgs(wxConvertMB2WX(pCmdLine), argc);
83
84 return wxEntry(argc, argv);
85}
86
2bda0e17 87// May wish not to have a DllMain or WinMain, e.g. if we're programming
b568d04f 88// a Netscape plugin or if we're writing a console application
94826170 89#if !defined(NOMAIN)
2bda0e17 90
e2478fde
VZ
91extern "C"
92{
2bda0e17 93
e2478fde 94// ----------------------------------------------------------------------------
2bda0e17 95// WinMain
e2478fde
VZ
96// ----------------------------------------------------------------------------
97
2bda0e17
KB
98// Note that WinMain is also defined in dummy.obj, which is linked to
99// an application that is using the DLL version of wxWindows.
100
101#if !defined(_WINDLL)
102
8f177c8e
VZ
103int PASCAL WinMain(HINSTANCE hInstance,
104 HINSTANCE hPrevInstance,
105 LPSTR lpCmdLine,
106 int nCmdShow)
2bda0e17 107{
13bdd545 108 return wxEntry(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
2bda0e17 109}
8f177c8e 110
e2478fde 111#else // _WINDLL
2bda0e17
KB
112
113// DLL entry point
114
e2478fde
VZ
115BOOL WINAPI
116DllMain(HANDLE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved))
2bda0e17 117{
e2478fde
VZ
118 // Only call wxEntry if the application itself is part of the DLL.
119 // If only the wxWindows library is in the DLL, then the
120 // initialisation will be called when the application implicitly
121 // calls WinMain.
beed393c 122#ifndef WXMAKINGDLL
2bda0e17 123 switch (fdwReason)
b568d04f
VZ
124 {
125 case DLL_PROCESS_ATTACH:
13bdd545 126 return wxEntry(hModule);
2bda0e17 127
b568d04f 128 case DLL_PROCESS_DETACH:
94826170
VZ
129 wxEntryCleanup();
130 break;
b568d04f 131 }
33ac7e6f
KB
132#else
133 (void)hModule;
134 (void)fdwReason;
beed393c 135#endif // !WXMAKINGDLL
e2478fde 136
b568d04f 137 return TRUE;
2bda0e17
KB
138}
139
e2478fde
VZ
140#endif // _WINDLL/!_WINDLL
141
142} // extern "C"
2bda0e17 143
b568d04f
VZ
144#endif // !NOMAIN
145
94826170
VZ
146// ---------------------------------------------------------------------------
147// Convert Windows to argc, argv style
148// ---------------------------------------------------------------------------
149
150wxChar **ConvertToStandardCommandArgs(const wxChar *p, int& argc)
151{
152 // break the command line in words
153 wxArrayString args;
154 if ( p )
155 {
156 args = wxCmdLineParser::ConvertStringToArgs(p);
157 }
158
159 // +1 here for the program name
160 argc = args.GetCount() + 1;
161
162 // and +1 here for the terminating NULL
163 wxChar **argv = new wxChar *[argc + 1];
164
165 argv[0] = new wxChar[MAX_PATH];
166 ::GetModuleFileName(wxhInstance, argv[0], MAX_PATH);
167
168 // copy all the other arguments to wxApp::argv[]
169 for ( int i = 1; i < argc; i++ )
170 {
171 argv[i] = wxStrdup(args[i - 1]);
172 }
173
174 // argv[] must be NULL-terminated
175 argv[argc] = NULL;
176
177 return argv;
178}
179
180#endif // wxUSE_GUI
181
b568d04f 182// ----------------------------------------------------------------------------
e2478fde 183// global HINSTANCE
b568d04f
VZ
184// ----------------------------------------------------------------------------
185
ec67cff1 186#if wxUSE_BASE
e2478fde
VZ
187
188HINSTANCE wxhInstance = 0;
189
b568d04f
VZ
190HINSTANCE wxGetInstance()
191{
192 return wxhInstance;
193}
194
195void wxSetInstance(HINSTANCE hInst)
196{
197 wxhInstance = hInst;
198}
2bda0e17 199
ec67cff1 200#endif // wxUSE_BASE
e2478fde 201