Remove dynamic loading of SHAutoComplete.

Available since Win2k.
This commit is contained in:
Tobias Taschner
2015-09-16 00:06:43 +02:00
parent 977da25524
commit 615b932f72
2 changed files with 8 additions and 53 deletions

View File

@@ -39,6 +39,9 @@
#include "wx/msw/uxtheme.h" #include "wx/msw/uxtheme.h"
#endif #endif
#include "wx/msw/wrapwin.h"
#include <Shlwapi.h>
#define GetEditHwnd() ((HWND)(GetEditHWND())) #define GetEditHwnd() ((HWND)(GetEditHWND()))
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -775,24 +778,6 @@ void wxTextEntry::GetSelection(long *from, long *to) const
bool wxTextEntry::DoAutoCompleteFileNames(int flags) bool wxTextEntry::DoAutoCompleteFileNames(int flags)
{ {
typedef HRESULT (WINAPI *SHAutoComplete_t)(HWND, DWORD);
static SHAutoComplete_t s_pfnSHAutoComplete = (SHAutoComplete_t)-1;
static wxDynamicLibrary s_dllShlwapi;
if ( s_pfnSHAutoComplete == (SHAutoComplete_t)-1 )
{
if ( !s_dllShlwapi.Load(wxT("shlwapi.dll"), wxDL_VERBATIM | wxDL_QUIET) )
{
s_pfnSHAutoComplete = NULL;
}
else
{
wxDL_INIT_FUNC(s_pfn, SHAutoComplete, s_dllShlwapi);
}
}
if ( !s_pfnSHAutoComplete )
return false;
DWORD dwFlags = 0; DWORD dwFlags = 0;
if ( flags & wxFILE ) if ( flags & wxFILE )
dwFlags |= SHACF_FILESYS_ONLY; dwFlags |= SHACF_FILESYS_ONLY;
@@ -804,7 +789,7 @@ bool wxTextEntry::DoAutoCompleteFileNames(int flags)
return false; return false;
} }
HRESULT hr = (*s_pfnSHAutoComplete)(GetEditHwnd(), dwFlags); HRESULT hr = ::SHAutoComplete(GetEditHwnd(), dwFlags);
if ( FAILED(hr) ) if ( FAILED(hr) )
{ {
wxLogApiError(wxT("SHAutoComplete()"), hr); wxLogApiError(wxT("SHAutoComplete()"), hr);

View File

@@ -29,10 +29,11 @@
#include "wx/utils.h" #include "wx/utils.h"
#endif //WX_PRECOMP #endif //WX_PRECOMP
#include "wx/dynlib.h"
#include "wx/msw/private.h" // includes <windows.h> #include "wx/msw/private.h" // includes <windows.h>
#include "wx/msw/wrapwin.h"
#include <Shlwapi.h>
// ============================================================================ // ============================================================================
// implementation // implementation
// ============================================================================ // ============================================================================
@@ -264,34 +265,7 @@ void wxDrawLine(HDC hdc, int x1, int y1, int x2, int y2)
extern bool wxEnableFileNameAutoComplete(HWND hwnd) extern bool wxEnableFileNameAutoComplete(HWND hwnd)
{ {
#if wxUSE_DYNLIB_CLASS HRESULT hr = ::SHAutoComplete(hwnd, 0x10 /* SHACF_FILESYS_ONLY */);
typedef HRESULT (WINAPI *SHAutoComplete_t)(HWND, DWORD);
static SHAutoComplete_t s_pfnSHAutoComplete = NULL;
static bool s_initialized = false;
if ( !s_initialized )
{
s_initialized = true;
wxLogNull nolog;
wxDynamicLibrary dll(wxT("shlwapi.dll"));
if ( dll.IsLoaded() )
{
s_pfnSHAutoComplete =
(SHAutoComplete_t)dll.GetSymbol(wxT("SHAutoComplete"));
if ( s_pfnSHAutoComplete )
{
// won't be unloaded until the process termination, no big deal
dll.Detach();
}
}
}
if ( !s_pfnSHAutoComplete )
return false;
HRESULT hr = s_pfnSHAutoComplete(hwnd, 0x10 /* SHACF_FILESYS_ONLY */);
if ( FAILED(hr) ) if ( FAILED(hr) )
{ {
wxLogApiError(wxT("SHAutoComplete"), hr); wxLogApiError(wxT("SHAutoComplete"), hr);
@@ -299,8 +273,4 @@ extern bool wxEnableFileNameAutoComplete(HWND hwnd)
} }
return true; return true;
#else
wxUnusedVar(hwnd);
return false;
#endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS
} }