]>
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.
103 DllMain(HANDLE hModule
, DWORD fdwReason
, LPVOID
WXUNUSED(lpReserved
))
105 // Only call wxEntry if the application itself is part of the DLL.
106 // If only the wxWindows library is in the DLL, then the
107 // initialisation will be called when the application implicitly
112 case DLL_PROCESS_ATTACH
:
113 return wxEntry(hModule
);
115 case DLL_PROCESS_DETACH
:
122 #endif // !WXMAKINGDLL
133 // ---------------------------------------------------------------------------
134 // Convert Windows to argc, argv style
135 // ---------------------------------------------------------------------------
137 wxChar
**ConvertToStandardCommandArgs(const wxChar
*p
, int& argc
)
139 // break the command line in words
143 args
= wxCmdLineParser::ConvertStringToArgs(p
);
146 // +1 here for the program name
147 argc
= args
.GetCount() + 1;
149 // and +1 here for the terminating NULL
150 wxChar
**argv
= new wxChar
*[argc
+ 1];
152 // as we use wxStrdup below we must allocate the first argument using
153 // malloc(), not new[], as well
154 argv
[0] = (wxChar
*)malloc(MAX_PATH
* sizeof(wxChar
));
155 ::GetModuleFileName(wxhInstance
, argv
[0], MAX_PATH
);
157 // copy all the other arguments to wxApp::argv[]
158 for ( int i
= 1; i
< argc
; i
++ )
160 argv
[i
] = wxStrdup(args
[i
- 1]);
163 // argv[] must be NULL-terminated
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
177 HINSTANCE wxhInstance
= 0;
179 HINSTANCE
wxGetInstance()
184 void wxSetInstance(HINSTANCE hInst
)