wxBase/GUI separation: 1st step, wxMSW should build, all the rest is broken
[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 #ifdef __GNUG__
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
34 #include "wx/msw/private.h"
35
36 // Don't implement WinMain if we're building an MFC/wxWindows hybrid app.
37 #if wxUSE_MFC && !defined(NOMAIN)
38 #define NOMAIN 1
39 #endif
40
41 #ifdef __BORLANDC__
42 // BC++ has to be special: its run-time expects the DLL entry point to be
43 // named DllEntryPoint instead of the (more) standard DllMain
44 #define DllMain DllEntryPoint
45 #endif
46
47 #if defined(__WXMICROWIN__)
48 #define HINSTANCE HANDLE
49 #endif
50
51 // ----------------------------------------------------------------------------
52 // function prototypes
53 // ----------------------------------------------------------------------------
54
55 // from src/msw/app.cpp
56 extern void WXDLLEXPORT wxEntryCleanup();
57
58 // ============================================================================
59 // implementation: various entry points
60 // ============================================================================
61
62 // May wish not to have a DllMain or WinMain, e.g. if we're programming
63 // a Netscape plugin or if we're writing a console application
64 #if wxUSE_GUI && !defined(NOMAIN)
65
66 extern "C"
67 {
68
69 // ----------------------------------------------------------------------------
70 // WinMain
71 // ----------------------------------------------------------------------------
72
73 // Note that WinMain is also defined in dummy.obj, which is linked to
74 // an application that is using the DLL version of wxWindows.
75
76 #if !defined(_WINDLL)
77
78 int PASCAL WinMain(HINSTANCE hInstance,
79 HINSTANCE hPrevInstance,
80 LPSTR lpCmdLine,
81 int nCmdShow)
82 {
83 return wxEntry((WXHINSTANCE) hInstance,
84 (WXHINSTANCE) hPrevInstance,
85 lpCmdLine,
86 nCmdShow);
87 }
88
89 #else // _WINDLL
90
91 // DLL entry point
92
93 BOOL WINAPI
94 DllMain(HANDLE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved))
95 {
96 // Only call wxEntry if the application itself is part of the DLL.
97 // If only the wxWindows library is in the DLL, then the
98 // initialisation will be called when the application implicitly
99 // calls WinMain.
100 #ifndef WXMAKINGDLL
101 switch (fdwReason)
102 {
103 case DLL_PROCESS_ATTACH:
104 return wxEntry((WXHINSTANCE) hModule);
105
106 case DLL_PROCESS_DETACH:
107 if ( wxTheApp )
108 wxTheApp->OnExit();
109 wxEntryCleanup();
110 break;
111 }
112 #else
113 (void)hModule;
114 (void)fdwReason;
115 #endif // !WXMAKINGDLL
116
117 return TRUE;
118 }
119
120 #endif // _WINDLL/!_WINDLL
121
122 } // extern "C"
123
124 #endif // !NOMAIN
125
126 // ----------------------------------------------------------------------------
127 // global HINSTANCE
128 // ----------------------------------------------------------------------------
129
130 #ifdef __WXBASE__
131
132 HINSTANCE wxhInstance = 0;
133
134 HINSTANCE wxGetInstance()
135 {
136 return wxhInstance;
137 }
138
139 void wxSetInstance(HINSTANCE hInst)
140 {
141 wxhInstance = hInst;
142 }
143
144 #endif // __WXBASE__
145