]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/main.cpp
13c6321b2bb40e563e23399b88451127b2efadb4
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"
34 #include "wx/cmdline.h"
36 #include "wx/msw/private.h"
38 // Don't implement WinMain if we're building an MFC/wxWindows hybrid app.
39 #if wxUSE_MFC && !defined(NOMAIN)
44 // BC++ has to be special: its run-time expects the DLL entry point to be
45 // named DllEntryPoint instead of the (more) standard DllMain
46 #define DllMain DllEntryPoint
49 #if defined(__WXMICROWIN__)
50 #define HINSTANCE HANDLE
55 // ----------------------------------------------------------------------------
56 // function prototypes
57 // ----------------------------------------------------------------------------
59 // from src/msw/app.cpp
60 extern void WXDLLEXPORT
wxEntryCleanup();
62 static wxChar
**ConvertToStandardCommandArgs(const wxChar
*p
, int& argc
);
64 // ============================================================================
65 // implementation: various entry points
66 // ============================================================================
68 // ----------------------------------------------------------------------------
69 // Windows-specific wxEntry
70 // ----------------------------------------------------------------------------
72 int wxEntry(WXHINSTANCE hInstance
,
73 WXHINSTANCE
WXUNUSED(hPrevInstance
),
77 // remember the parameters Windows gave us
78 wxSetInstance((HINSTANCE
)hInstance
);
79 wxApp::m_nCmdShow
= nCmdShow
;
81 // parse the command line
83 wxChar
**argv
= ConvertToStandardCommandArgs(wxConvertMB2WX(pCmdLine
), argc
);
85 return wxEntry(argc
, argv
);
88 // May wish not to have a DllMain or WinMain, e.g. if we're programming
89 // a Netscape plugin or if we're writing a console application
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 // Note that WinMain is also defined in dummy.obj, which is linked to
100 // an application that is using the DLL version of wxWindows.
102 #if !defined(_WINDLL)
104 int PASCAL
WinMain(HINSTANCE hInstance
,
105 HINSTANCE hPrevInstance
,
109 return wxEntry((WXHINSTANCE
) hInstance
,
110 (WXHINSTANCE
) hPrevInstance
,
120 DllMain(HANDLE hModule
, DWORD fdwReason
, LPVOID
WXUNUSED(lpReserved
))
122 // Only call wxEntry if the application itself is part of the DLL.
123 // If only the wxWindows library is in the DLL, then the
124 // initialisation will be called when the application implicitly
129 case DLL_PROCESS_ATTACH
:
130 return wxEntry((WXHINSTANCE
) hModule
);
132 case DLL_PROCESS_DETACH
:
139 #endif // !WXMAKINGDLL
144 #endif // _WINDLL/!_WINDLL
150 // ---------------------------------------------------------------------------
151 // Convert Windows to argc, argv style
152 // ---------------------------------------------------------------------------
154 wxChar
**ConvertToStandardCommandArgs(const wxChar
*p
, int& argc
)
156 // break the command line in words
160 args
= wxCmdLineParser::ConvertStringToArgs(p
);
163 // +1 here for the program name
164 argc
= args
.GetCount() + 1;
166 // and +1 here for the terminating NULL
167 wxChar
**argv
= new wxChar
*[argc
+ 1];
169 argv
[0] = new wxChar
[MAX_PATH
];
170 ::GetModuleFileName(wxhInstance
, argv
[0], MAX_PATH
);
172 // copy all the other arguments to wxApp::argv[]
173 for ( int i
= 1; i
< argc
; i
++ )
175 argv
[i
] = wxStrdup(args
[i
- 1]);
178 // argv[] must be NULL-terminated
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
192 HINSTANCE wxhInstance
= 0;
194 HINSTANCE
wxGetInstance()
199 void wxSetInstance(HINSTANCE hInst
)