added wxMSW-specific wxEntryStart() overload taking WinMain-like parameters
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46203 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -435,6 +435,15 @@ least the GUI part of) the library can't be used at all.
|
|||||||
Notice that parameters \arg{argc} and \arg{argv} may be modified by this
|
Notice that parameters \arg{argc} and \arg{argv} may be modified by this
|
||||||
function.
|
function.
|
||||||
|
|
||||||
|
An additional overload of wxEntryStart() is provided under MSW only: it is
|
||||||
|
meant to be called with the parameters passed to \texttt{WinMain()}.
|
||||||
|
|
||||||
|
\func{bool}{wxEntryStart}{\param{HINSTANCE }{hInstance}, \param{HINSTANCE }{hPrevInstance = \NULL}, \param{char *}{pCmdLine = \NULL}, \param{int }{nCmdShow = \texttt{SW\_SHOWNORMAL}}}
|
||||||
|
|
||||||
|
(notice that under Windows CE platform, and only there, the type of
|
||||||
|
\arg{pCmdLine} is \texttt{wchar\_t *}, otherwise it is \texttt{char *}, even in
|
||||||
|
Unicode build).
|
||||||
|
|
||||||
\wxheading{Include files}
|
\wxheading{Include files}
|
||||||
|
|
||||||
<wx/init.h>
|
<wx/init.h>
|
||||||
|
@@ -96,6 +96,14 @@ protected:
|
|||||||
typedef char *wxCmdLineArgType;
|
typedef char *wxCmdLineArgType;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// wxMSW-only overloads of wxEntry() and wxEntryStart() which take the
|
||||||
|
// parameters passed to WinMain() instead of those passed to main()
|
||||||
|
extern bool WXDLLEXPORT
|
||||||
|
wxEntryStart(HINSTANCE hInstance,
|
||||||
|
HINSTANCE hPrevInstance = NULL,
|
||||||
|
wxCmdLineArgType pCmdLine = NULL,
|
||||||
|
int nCmdShow = SW_SHOWNORMAL);
|
||||||
|
|
||||||
extern int WXDLLEXPORT
|
extern int WXDLLEXPORT
|
||||||
wxEntry(HINSTANCE hInstance,
|
wxEntry(HINSTANCE hInstance,
|
||||||
HINSTANCE hPrevInstance = NULL,
|
HINSTANCE hPrevInstance = NULL,
|
||||||
|
@@ -61,6 +61,7 @@
|
|||||||
|
|
||||||
// defined in common/init.cpp
|
// defined in common/init.cpp
|
||||||
extern int wxEntryReal(int& argc, wxChar **argv);
|
extern int wxEntryReal(int& argc, wxChar **argv);
|
||||||
|
extern int wxEntryCleanupReal(int& argc, wxChar **argv);
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// implementation: various entry points
|
// implementation: various entry points
|
||||||
@@ -319,31 +320,56 @@ static bool wxIsUnicodeAvailable()
|
|||||||
// Windows-specific wxEntry
|
// Windows-specific wxEntry
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// helper function used to clean up in wxEntry() just below
|
struct wxMSWCommandLineArguments
|
||||||
//
|
|
||||||
// notice that argv elements are supposed to be allocated using malloc() while
|
|
||||||
// argv array itself is allocated with new
|
|
||||||
static void wxFreeArgs(int argc, wxChar **argv)
|
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < argc; i++ )
|
wxMSWCommandLineArguments() { argc = 0; argv = NULL; }
|
||||||
|
|
||||||
|
void Init(const wxArrayString& args)
|
||||||
{
|
{
|
||||||
free(argv[i]);
|
argc = args.size();
|
||||||
|
|
||||||
|
// +1 here for the terminating NULL
|
||||||
|
argv = new wxChar *[argc + 1];
|
||||||
|
for ( int i = 0; i < argc; i++ )
|
||||||
|
{
|
||||||
|
argv[i] = wxStrdup(args[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// argv[] must be NULL-terminated
|
||||||
|
argv[argc] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] argv;
|
void Free()
|
||||||
}
|
{
|
||||||
|
if ( !argc )
|
||||||
|
return;
|
||||||
|
|
||||||
WXDLLEXPORT int wxEntry(HINSTANCE hInstance,
|
for ( int i = 0; i < argc; i++ )
|
||||||
HINSTANCE WXUNUSED(hPrevInstance),
|
{
|
||||||
wxCmdLineArgType WXUNUSED(pCmdLine),
|
free(argv[i]);
|
||||||
int nCmdShow)
|
}
|
||||||
|
|
||||||
|
delete [] argv;
|
||||||
|
argv = NULL;
|
||||||
|
argc = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int argc;
|
||||||
|
wxChar **argv;
|
||||||
|
};
|
||||||
|
|
||||||
|
static wxMSWCommandLineArguments wxArgs;
|
||||||
|
|
||||||
|
// common part of wxMSW-specific wxEntryStart() and wxEntry() overloads
|
||||||
|
static bool
|
||||||
|
wxMSWEntryCommon(HINSTANCE hInstance, int nCmdShow)
|
||||||
{
|
{
|
||||||
// the first thing to do is to check if we're trying to run an Unicode
|
// the first thing to do is to check if we're trying to run an Unicode
|
||||||
// program under Win9x w/o MSLU emulation layer - if so, abort right now
|
// program under Win9x w/o MSLU emulation layer - if so, abort right now
|
||||||
// as it has no chance to work and has all chances to crash
|
// as it has no chance to work and has all chances to crash
|
||||||
#ifdef NEED_UNICODE_CHECK
|
#ifdef NEED_UNICODE_CHECK
|
||||||
if ( !wxIsUnicodeAvailable() )
|
if ( !wxIsUnicodeAvailable() )
|
||||||
return -1;
|
return false;
|
||||||
#endif // NEED_UNICODE_CHECK
|
#endif // NEED_UNICODE_CHECK
|
||||||
|
|
||||||
|
|
||||||
@@ -369,21 +395,33 @@ WXDLLEXPORT int wxEntry(HINSTANCE hInstance,
|
|||||||
args.Insert(wxGetFullModuleName(), 0);
|
args.Insert(wxGetFullModuleName(), 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int argc = args.GetCount();
|
wxArgs.Init(args);
|
||||||
|
|
||||||
// +1 here for the terminating NULL
|
return true;
|
||||||
wxChar **argv = new wxChar *[argc + 1];
|
}
|
||||||
for ( int i = 0; i < argc; i++ )
|
|
||||||
{
|
|
||||||
argv[i] = wxStrdup(args[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// argv[] must be NULL-terminated
|
WXDLLEXPORT bool wxEntryStart(HINSTANCE hInstance,
|
||||||
argv[argc] = NULL;
|
HINSTANCE WXUNUSED(hPrevInstance),
|
||||||
|
wxCmdLineArgType WXUNUSED(pCmdLine),
|
||||||
|
int nCmdShow)
|
||||||
|
{
|
||||||
|
if ( !wxMSWEntryCommon(hInstance, nCmdShow) )
|
||||||
|
return false;
|
||||||
|
|
||||||
wxON_BLOCK_EXIT2(wxFreeArgs, argc, argv);
|
return wxEntryStart(wxArgs.argc, wxArgs.argv);
|
||||||
|
}
|
||||||
|
|
||||||
return wxEntry(argc, argv);
|
WXDLLEXPORT int wxEntry(HINSTANCE hInstance,
|
||||||
|
HINSTANCE WXUNUSED(hPrevInstance),
|
||||||
|
wxCmdLineArgType WXUNUSED(pCmdLine),
|
||||||
|
int nCmdShow)
|
||||||
|
{
|
||||||
|
if ( !wxMSWEntryCommon(hInstance, nCmdShow) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
wxON_BLOCK_EXIT_OBJ0(wxArgs, wxMSWCommandLineArguments::Free);
|
||||||
|
|
||||||
|
return wxEntry(wxArgs.argc, wxArgs.argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_GUI && __WXMSW__
|
#endif // wxUSE_GUI && __WXMSW__
|
||||||
|
Reference in New Issue
Block a user