]> git.saurik.com Git - wxWidgets.git/blame - src/msw/main.cpp
use a linked list instead of array for saved messages to fix problems when Dispatch...
[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 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
57WXDLLEXPORT 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;
13a5a49f 72
b2b1371c
VZ
73 const wxChar *cmdLine = ::GetCommandLine();
74 if ( cmdLine )
75 {
76 args = wxCmdLineParser::ConvertStringToArgs(cmdLine);
77 }
78
13a5a49f 79#ifdef __WXWINCE__
77d8d6cd
VZ
80 // WinCE doesn't insert the program itself, so do it ourselves.
81 args.Insert(wxGetFullModuleName(), 0);
13a5a49f
JS
82#endif
83
b2b1371c
VZ
84 int argc = args.GetCount();
85
86 // +1 here for the terminating NULL
87 wxChar **argv = new wxChar *[argc + 1];
88 for ( int i = 0; i < argc; i++ )
89 {
90 argv[i] = wxStrdup(args[i]);
91 }
92
93 // argv[] must be NULL-terminated
94 argv[argc] = NULL;
94826170
VZ
95
96 return wxEntry(argc, argv);
97}
98
2bda0e17 99// May wish not to have a DllMain or WinMain, e.g. if we're programming
b568d04f 100// a Netscape plugin or if we're writing a console application
94826170 101#if !defined(NOMAIN)
2bda0e17 102
e2478fde
VZ
103extern "C"
104{
2bda0e17 105
e2478fde 106// ----------------------------------------------------------------------------
2bda0e17 107// WinMain
e2478fde
VZ
108// ----------------------------------------------------------------------------
109
2bda0e17 110// Note that WinMain is also defined in dummy.obj, which is linked to
77ffb593 111// an application that is using the DLL version of wxWidgets.
2bda0e17 112
ac9a3c61 113#if defined(_WINDLL)
2bda0e17
KB
114
115// DLL entry point
116
e2478fde
VZ
117BOOL WINAPI
118DllMain(HANDLE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved))
2bda0e17 119{
e2478fde 120 // Only call wxEntry if the application itself is part of the DLL.
77ffb593 121 // If only the wxWidgets library is in the DLL, then the
e2478fde
VZ
122 // initialisation will be called when the application implicitly
123 // calls WinMain.
beed393c 124#ifndef WXMAKINGDLL
2bda0e17 125 switch (fdwReason)
b568d04f
VZ
126 {
127 case DLL_PROCESS_ATTACH:
13bdd545 128 return wxEntry(hModule);
2bda0e17 129
b568d04f 130 case DLL_PROCESS_DETACH:
94826170
VZ
131 wxEntryCleanup();
132 break;
b568d04f 133 }
33ac7e6f 134#else
598ddd96
WS
135 (void)hModule;
136 (void)fdwReason;
beed393c 137#endif // !WXMAKINGDLL
e2478fde 138
b568d04f 139 return TRUE;
2bda0e17
KB
140}
141
ac9a3c61 142#endif // _WINDLL
e2478fde
VZ
143
144} // extern "C"
2bda0e17 145
b568d04f
VZ
146#endif // !NOMAIN
147
94826170
VZ
148#endif // wxUSE_GUI
149
b568d04f 150// ----------------------------------------------------------------------------
e2478fde 151// global HINSTANCE
b568d04f
VZ
152// ----------------------------------------------------------------------------
153
ec67cff1 154#if wxUSE_BASE
e2478fde
VZ
155
156HINSTANCE wxhInstance = 0;
157
b568d04f
VZ
158HINSTANCE wxGetInstance()
159{
160 return wxhInstance;
161}
162
163void wxSetInstance(HINSTANCE hInst)
164{
165 wxhInstance = hInst;
166}
2bda0e17 167
ec67cff1 168#endif // wxUSE_BASE
e2478fde 169