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