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