]>
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)
103 int PASCAL
WinMain(HINSTANCE hInstance
,
104 HINSTANCE hPrevInstance
,
108 return wxEntry(hInstance
, hPrevInstance
, lpCmdLine
, nCmdShow
);
116 DllMain(HANDLE hModule
, DWORD fdwReason
, LPVOID
WXUNUSED(lpReserved
))
118 // Only call wxEntry if the application itself is part of the DLL.
119 // If only the wxWindows library is in the DLL, then the
120 // initialisation will be called when the application implicitly
125 case DLL_PROCESS_ATTACH
:
126 return wxEntry(hModule
);
128 case DLL_PROCESS_DETACH
:
135 #endif // !WXMAKINGDLL
140 #endif // _WINDLL/!_WINDLL
146 // ---------------------------------------------------------------------------
147 // Convert Windows to argc, argv style
148 // ---------------------------------------------------------------------------
150 wxChar
**ConvertToStandardCommandArgs(const wxChar
*p
, int& argc
)
152 // break the command line in words
156 args
= wxCmdLineParser::ConvertStringToArgs(p
);
159 // +1 here for the program name
160 argc
= args
.GetCount() + 1;
162 // and +1 here for the terminating NULL
163 wxChar
**argv
= new wxChar
*[argc
+ 1];
165 argv
[0] = new wxChar
[MAX_PATH
];
166 ::GetModuleFileName(wxhInstance
, argv
[0], MAX_PATH
);
168 // copy all the other arguments to wxApp::argv[]
169 for ( int i
= 1; i
< argc
; i
++ )
171 argv
[i
] = wxStrdup(args
[i
- 1]);
174 // argv[] must be NULL-terminated
182 // ----------------------------------------------------------------------------
184 // ----------------------------------------------------------------------------
188 HINSTANCE wxhInstance
= 0;
190 HINSTANCE
wxGetInstance()
195 void wxSetInstance(HINSTANCE hInst
)