MFC sample now works properly; WinMain not defined in wxMSW
[wxWidgets.git] / src / msw / main.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/main.cpp
3 // Purpose: Main/DllMain
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
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
37 // hybrid app.
38 #if wxUSE_MFC && !defined(NOMAIN)
39 #define NOMAIN 1
40 #endif
41
42 // from src/msw/app.cpp
43 extern void WXDLLEXPORT wxEntryCleanup();
44
45 // ----------------------------------------------------------------------------
46 // globals
47 // ----------------------------------------------------------------------------
48
49 HINSTANCE wxhInstance = 0;
50
51 // ============================================================================
52 // implementation
53 // ============================================================================
54
55 // ----------------------------------------------------------------------------
56 // various entry points
57 // ----------------------------------------------------------------------------
58
59 // May wish not to have a DllMain or WinMain, e.g. if we're programming
60 // a Netscape plugin or if we're writing a console application
61 #if wxUSE_GUI && !defined(NOMAIN)
62
63 // NT defines APIENTRY, 3.x not
64 #if !defined(APIENTRY)
65 #define APIENTRY FAR PASCAL
66 #endif
67
68 /////////////////////////////////////////////////////////////////////////////////
69 // WinMain
70 // Note that WinMain is also defined in dummy.obj, which is linked to
71 // an application that is using the DLL version of wxWindows.
72
73 #if !defined(_WINDLL)
74
75 #if defined(__WXWINE__)
76 #define HINSTANCE HINSTANCE__*
77
78 extern "C"
79 #elif defined(__TWIN32__) || defined(__WXMICROWIN__)
80 #define HINSTANCE HANDLE
81
82 extern "C"
83 #endif // WINE
84
85 int PASCAL WinMain(HINSTANCE hInstance,
86 HINSTANCE hPrevInstance,
87 LPSTR lpCmdLine,
88 int nCmdShow)
89 {
90 return wxEntry((WXHINSTANCE) hInstance, (WXHINSTANCE) hPrevInstance,
91 lpCmdLine, nCmdShow);
92 }
93
94 #endif // !defined(_WINDLL)
95
96 /////////////////////////////////////////////////////////////////////////////////
97 // DllMain
98
99 #if defined(_WINDLL)
100
101 // DLL entry point
102
103 extern "C"
104 #ifdef __BORLANDC__
105 // SCD: I don't know why, but also OWL uses this function
106 BOOL WINAPI DllEntryPoint (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
107 #else
108 BOOL WINAPI DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
109 #endif
110 {
111 #ifndef WXMAKINGDLL
112 switch (fdwReason)
113 {
114 case DLL_PROCESS_ATTACH:
115 // Only call wxEntry if the application itself is part of the DLL.
116 // If only the wxWindows library is in the DLL, then the
117 // initialisation will be called when the application implicitly
118 // calls WinMain.
119 return wxEntry((WXHINSTANCE) hModule);
120
121 case DLL_PROCESS_DETACH:
122 if ( wxTheApp )
123 wxTheApp->OnExit();
124 wxEntryCleanup();
125 break;
126 }
127 #else
128 (void)hModule;
129 (void)fdwReason;
130 #endif // !WXMAKINGDLL
131 (void)lpReserved;
132 return TRUE;
133 }
134
135 #endif // _WINDLL
136
137 #endif // !NOMAIN
138
139 // ----------------------------------------------------------------------------
140 // global functions
141 // ----------------------------------------------------------------------------
142
143 HINSTANCE wxGetInstance()
144 {
145 return wxhInstance;
146 }
147
148 void wxSetInstance(HINSTANCE hInst)
149 {
150 wxhInstance = hInst;
151 }
152