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