]>
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 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 static wxChar
**ConvertToStandardCommandArgs(const wxChar
*p
, int& argc
);
60 // ============================================================================
61 // implementation: various entry points
62 // ============================================================================
64 // ----------------------------------------------------------------------------
65 // Windows-specific wxEntry
66 // ----------------------------------------------------------------------------
68 WXDLLEXPORT
int wxEntry(HINSTANCE hInstance
,
69 HINSTANCE
WXUNUSED(hPrevInstance
),
73 // remember the parameters Windows gave us
74 wxSetInstance(hInstance
);
75 wxApp::m_nCmdShow
= nCmdShow
;
77 // parse the command line
79 wxChar
**argv
= ConvertToStandardCommandArgs(wxConvertMB2WX(pCmdLine
), argc
);
81 return wxEntry(argc
, argv
);
84 // May wish not to have a DllMain or WinMain, e.g. if we're programming
85 // a Netscape plugin or if we're writing a console application
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 // Note that WinMain is also defined in dummy.obj, which is linked to
96 // an application that is using the DLL version of wxWindows.
101 int WINAPI
WinMain(HINSTANCE hInstance
,
102 HINSTANCE hPrevInstance
,
106 return wxEntry(hInstance
, hPrevInstance
, (char*) lpCmdLine
, nCmdShow
);
109 int PASCAL
WinMain(HINSTANCE hInstance
,
110 HINSTANCE hPrevInstance
,
114 return wxEntry(hInstance
, hPrevInstance
, lpCmdLine
, nCmdShow
);
123 DllMain(HANDLE hModule
, DWORD fdwReason
, LPVOID
WXUNUSED(lpReserved
))
125 // Only call wxEntry if the application itself is part of the DLL.
126 // If only the wxWindows library is in the DLL, then the
127 // initialisation will be called when the application implicitly
132 case DLL_PROCESS_ATTACH
:
133 return wxEntry(hModule
);
135 case DLL_PROCESS_DETACH
:
142 #endif // !WXMAKINGDLL
147 #endif // _WINDLL/!_WINDLL
153 // ---------------------------------------------------------------------------
154 // Convert Windows to argc, argv style
155 // ---------------------------------------------------------------------------
157 wxChar
**ConvertToStandardCommandArgs(const wxChar
*p
, int& argc
)
159 // break the command line in words
163 args
= wxCmdLineParser::ConvertStringToArgs(p
);
166 // +1 here for the program name
167 argc
= args
.GetCount() + 1;
169 // and +1 here for the terminating NULL
170 wxChar
**argv
= new wxChar
*[argc
+ 1];
172 // as we use wxStrdup below we must allocate the first argument using
173 // malloc(), not new[], as well
174 argv
[0] = (wxChar
*)malloc(MAX_PATH
* sizeof(wxChar
));
175 ::GetModuleFileName(wxhInstance
, argv
[0], MAX_PATH
);
177 // copy all the other arguments to wxApp::argv[]
178 for ( int i
= 1; i
< argc
; i
++ )
180 argv
[i
] = wxStrdup(args
[i
- 1]);
183 // argv[] must be NULL-terminated
191 // ----------------------------------------------------------------------------
193 // ----------------------------------------------------------------------------
197 HINSTANCE wxhInstance
= 0;
199 HINSTANCE
wxGetInstance()
204 void wxSetInstance(HINSTANCE hInst
)