]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
b568d04f | 2 | // Name: msw/main.cpp |
2bda0e17 KB |
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 | |
b568d04f | 9 | // Licence: wxWindows license |
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" |
b568d04f VZ |
33 | |
34 | #include "wx/msw/private.h" | |
35 | ||
4cd513ab JS |
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 | ||
beed393c VZ |
42 | // from src/msw/app.cpp |
43 | extern void WXDLLEXPORT wxEntryCleanup(); | |
44 | ||
b568d04f VZ |
45 | // ---------------------------------------------------------------------------- |
46 | // globals | |
47 | // ---------------------------------------------------------------------------- | |
48 | ||
49 | HINSTANCE wxhInstance = 0; | |
50 | ||
51 | // ============================================================================ | |
52 | // implementation | |
53 | // ============================================================================ | |
54 | ||
55 | // ---------------------------------------------------------------------------- | |
56 | // various entry points | |
57 | // ---------------------------------------------------------------------------- | |
2bda0e17 KB |
58 | |
59 | // May wish not to have a DllMain or WinMain, e.g. if we're programming | |
b568d04f VZ |
60 | // a Netscape plugin or if we're writing a console application |
61 | #if wxUSE_GUI && !defined(NOMAIN) | |
2bda0e17 KB |
62 | |
63 | // NT defines APIENTRY, 3.x not | |
64 | #if !defined(APIENTRY) | |
b568d04f | 65 | #define APIENTRY FAR PASCAL |
2bda0e17 KB |
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 | ||
3bce6687 JS |
75 | #if defined(__WXWINE__) |
76 | #define HINSTANCE HINSTANCE__* | |
77 | ||
78 | extern "C" | |
79 | #elif defined(__TWIN32__) || defined(__WXMICROWIN__) | |
8f177c8e | 80 | #define HINSTANCE HANDLE |
57c208c5 | 81 | |
8f177c8e VZ |
82 | extern "C" |
83 | #endif // WINE | |
57c208c5 | 84 | |
8f177c8e VZ |
85 | int PASCAL WinMain(HINSTANCE hInstance, |
86 | HINSTANCE hPrevInstance, | |
87 | LPSTR lpCmdLine, | |
88 | int nCmdShow) | |
2bda0e17 | 89 | { |
8f177c8e VZ |
90 | return wxEntry((WXHINSTANCE) hInstance, (WXHINSTANCE) hPrevInstance, |
91 | lpCmdLine, nCmdShow); | |
2bda0e17 | 92 | } |
8f177c8e VZ |
93 | |
94 | #endif // !defined(_WINDLL) | |
2bda0e17 KB |
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 | { | |
beed393c | 111 | #ifndef WXMAKINGDLL |
2bda0e17 | 112 | switch (fdwReason) |
b568d04f VZ |
113 | { |
114 | case DLL_PROCESS_ATTACH: | |
115 | // Only call wxEntry if the application itself is part of the DLL. | |
beed393c VZ |
116 | // If only the wxWindows library is in the DLL, then the |
117 | // initialisation will be called when the application implicitly | |
118 | // calls WinMain. | |
b568d04f | 119 | return wxEntry((WXHINSTANCE) hModule); |
2bda0e17 | 120 | |
b568d04f | 121 | case DLL_PROCESS_DETACH: |
beed393c VZ |
122 | if ( wxTheApp ) |
123 | wxTheApp->OnExit(); | |
124 | wxEntryCleanup(); | |
125 | break; | |
b568d04f | 126 | } |
33ac7e6f KB |
127 | #else |
128 | (void)hModule; | |
129 | (void)fdwReason; | |
beed393c | 130 | #endif // !WXMAKINGDLL |
33ac7e6f | 131 | (void)lpReserved; |
b568d04f | 132 | return TRUE; |
2bda0e17 KB |
133 | } |
134 | ||
b568d04f | 135 | #endif // _WINDLL |
2bda0e17 | 136 | |
b568d04f VZ |
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 | } | |
2bda0e17 | 152 |