From: Vadim Zeitlin Date: Mon, 27 Sep 2004 10:58:32 +0000 (+0000) Subject: added wxGetFullModuleName(); use it instead of calling ::GetModuleFileName() directly X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/77d8d6cd64c15837453362f386967b8a0bd22db9?hp=95ae6d5fc94004141f55ec4021c10ba9b558252e added wxGetFullModuleName(); use it instead of calling ::GetModuleFileName() directly git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29441 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index cef3f680db..b1ee23b549 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -46,6 +46,11 @@ static const double twips2mm = (1/(METRIC_CONVERSION_CONSTANT*1440)); static const double mm2pt = (METRIC_CONVERSION_CONSTANT*72); static const double pt2mm = (1/(METRIC_CONVERSION_CONSTANT*72)); +// 260 was taken from windef.h +#ifndef MAX_PATH + #define MAX_PATH 260 +#endif + // --------------------------------------------------------------------------- // standard icons from the resources // --------------------------------------------------------------------------- @@ -503,6 +508,23 @@ extern "C" WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst); +// return the full name of the program file +inline wxString wxGetFullModuleName() +{ + wxString fullname; + if ( !::GetModuleFileName + ( + (HMODULE)wxGetInstance(), + wxStringBuffer(fullname, MAX_PATH), + MAX_PATH + ) ) + { + wxLogLastError(_T("GetModuleFileName")); + } + + return fullname; +} + #if wxUSE_GUI // cursor stuff diff --git a/src/msw/main.cpp b/src/msw/main.cpp index 9d35d67001..a8bee7283b 100644 --- a/src/msw/main.cpp +++ b/src/msw/main.cpp @@ -77,15 +77,8 @@ WXDLLEXPORT int wxEntry(HINSTANCE hInstance, } #ifdef __WXWINCE__ - // WinCE doesn't insert the program itself, so let's - // do it here. - wxString programName; - - if ( ::GetModuleFileName( (HMODULE) wxGetInstance(), wxStringBuffer(programName, MAX_PATH), MAX_PATH ) == 0) - { - wxLogLastError(_T("GetModuleFileName")); - } - args.Insert(programName, 0); + // WinCE doesn't insert the program itself, so do it ourselves. + args.Insert(wxGetFullModuleName(), 0); #endif int argc = args.GetCount(); diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index eb91843d61..e7506b0908 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -94,11 +94,6 @@ #endif #endif -// 260 was taken from windef.h -#ifndef MAX_PATH - #define MAX_PATH 260 -#endif - // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -434,12 +429,8 @@ const wxChar* wxGetHomeDir(wxString *pstr) } else // fall back to the program directory { - wxString strPath; - ::GetModuleFileName(::GetModuleHandle(NULL), - wxStringBuffer(strPath, MAX_PATH), MAX_PATH); - - // extract the dir name - wxSplitPath(strPath, &strDir, NULL, NULL); + // extract the directory component of the program file name + wxSplitPath(wxGetFullModuleName(), &strDir, NULL, NULL); } #endif // UNIX/Win