From 55c76ed087ba64254eb75bd3b2dced5a60d15d09 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Thu, 8 Oct 2015 10:59:56 +0200 Subject: [PATCH] Remove dynamic loading of GetLongPathName. GetLongPathName is available since WinXP. --- src/common/filename.cpp | 59 +++++++---------------------------------- 1 file changed, 10 insertions(+), 49 deletions(-) diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 0e10d82916..1be39db2d3 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -2152,60 +2152,21 @@ wxString wxFileName::GetLongPath() const #if defined(__WIN32__) -#if wxUSE_DYNLIB_CLASS - typedef DWORD (WINAPI *GET_LONG_PATH_NAME)(const wxChar *, wxChar *, DWORD); - - // this is MT-safe as in the worst case we're going to resolve the function - // twice -- but as the result is the same in both threads, it's ok - static GET_LONG_PATH_NAME s_pfnGetLongPathName = NULL; - if ( !s_pfnGetLongPathName ) + DWORD dwSize = ::GetLongPathName(path.t_str(), NULL, 0); + if ( dwSize > 0 ) { - static bool s_triedToLoad = false; - - if ( !s_triedToLoad ) + if ( ::GetLongPathName + ( + path.t_str(), + wxStringBuffer(pathOut, dwSize), + dwSize + ) != 0 ) { - s_triedToLoad = true; - - wxDynamicLibrary dllKernel(wxT("kernel32")); - - const wxChar* GetLongPathName = wxT("GetLongPathName") -#if wxUSE_UNICODE - wxT("W"); -#else // ANSI - wxT("A"); -#endif // Unicode/ANSI - - if ( dllKernel.HasSymbol(GetLongPathName) ) - { - s_pfnGetLongPathName = (GET_LONG_PATH_NAME) - dllKernel.GetSymbol(GetLongPathName); - } - - // note that kernel32.dll can be unloaded, it stays in memory - // anyhow as all Win32 programs link to it and so it's safe to call - // GetLongPathName() even after unloading it + return pathOut; } } - if ( s_pfnGetLongPathName ) - { - DWORD dwSize = (*s_pfnGetLongPathName)(path.t_str(), NULL, 0); - if ( dwSize > 0 ) - { - if ( (*s_pfnGetLongPathName) - ( - path.t_str(), - wxStringBuffer(pathOut, dwSize), - dwSize - ) != 0 ) - { - return pathOut; - } - } - } -#endif // wxUSE_DYNLIB_CLASS - - // The OS didn't support GetLongPathName, or some other error. + // Some other error occured. // We need to call FindFirstFile on each component in turn. WIN32_FIND_DATA findFileData;