]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/main.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: WinMain/DllMain
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/cmdline.h"
35 #include "wx/msw/private.h"
37 // Don't implement WinMain if we're building an MFC/wxWindows hybrid app.
38 #if wxUSE_MFC && !defined(NOMAIN)
43 // BC++ has to be special: its run-time expects the DLL entry point to be
44 // named DllEntryPoint instead of the (more) standard DllMain
45 #define DllMain DllEntryPoint
48 #if defined(__WXMICROWIN__)
49 #define HINSTANCE HANDLE
54 // ----------------------------------------------------------------------------
55 // function prototypes
56 // ----------------------------------------------------------------------------
58 // from src/msw/app.cpp
59 extern void WXDLLEXPORT
wxEntryCleanup();
61 static wxChar
**ConvertToStandardCommandArgs(const wxChar
*p
, int& argc
);
63 // ============================================================================
64 // implementation: various entry points
65 // ============================================================================
67 // ----------------------------------------------------------------------------
68 // Windows-specific wxEntry
69 // ----------------------------------------------------------------------------
71 WXDLLEXPORT
int wxEntry(HINSTANCE hInstance
,
72 HINSTANCE
WXUNUSED(hPrevInstance
),
76 // remember the parameters Windows gave us
77 wxSetInstance(hInstance
);
78 wxApp::m_nCmdShow
= nCmdShow
;
80 // parse the command line
82 wxChar
**argv
= ConvertToStandardCommandArgs(wxConvertMB2WX(pCmdLine
), argc
);
84 return wxEntry(argc
, argv
);
87 // May wish not to have a DllMain or WinMain, e.g. if we're programming
88 // a Netscape plugin or if we're writing a console application
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 // Note that WinMain is also defined in dummy.obj, which is linked to
99 // an application that is using the DLL version of wxWindows.
101 #if !defined(_WINDLL)
104 int WINAPI
WinMain(HINSTANCE hInstance
,
105 HINSTANCE hPrevInstance
,
109 return wxEntry(hInstance
, hPrevInstance
, (char*) lpCmdLine
, nCmdShow
);
112 int PASCAL
WinMain(HINSTANCE hInstance
,
113 HINSTANCE hPrevInstance
,
117 return wxEntry(hInstance
, hPrevInstance
, lpCmdLine
, nCmdShow
);
126 DllMain(HANDLE hModule
, DWORD fdwReason
, LPVOID
WXUNUSED(lpReserved
))
128 // Only call wxEntry if the application itself is part of the DLL.
129 // If only the wxWindows library is in the DLL, then the
130 // initialisation will be called when the application implicitly
135 case DLL_PROCESS_ATTACH
:
136 return wxEntry(hModule
);
138 case DLL_PROCESS_DETACH
:
145 #endif // !WXMAKINGDLL
150 #endif // _WINDLL/!_WINDLL
156 // ---------------------------------------------------------------------------
157 // Convert Windows to argc, argv style
158 // ---------------------------------------------------------------------------
160 wxChar
**ConvertToStandardCommandArgs(const wxChar
*p
, int& argc
)
162 // break the command line in words
166 args
= wxCmdLineParser::ConvertStringToArgs(p
);
169 // +1 here for the program name
170 argc
= args
.GetCount() + 1;
172 // and +1 here for the terminating NULL
173 wxChar
**argv
= new wxChar
*[argc
+ 1];
175 argv
[0] = new wxChar
[MAX_PATH
];
176 ::GetModuleFileName(wxhInstance
, argv
[0], MAX_PATH
);
178 // copy all the other arguments to wxApp::argv[]
179 for ( int i
= 1; i
< argc
; i
++ )
181 argv
[i
] = wxStrdup(args
[i
- 1]);
184 // argv[] must be NULL-terminated
192 // ----------------------------------------------------------------------------
194 // ----------------------------------------------------------------------------
198 HINSTANCE wxhInstance
= 0;
200 HINSTANCE
wxGetInstance()
205 void wxSetInstance(HINSTANCE hInst
)