From 2bdd90ddfca69877734128808ebf4c46c21a90d8 Mon Sep 17 00:00:00 2001 From: walbourn_cp Date: Sun, 3 Feb 2013 16:06:01 -0800 Subject: [PATCH] Added WIC_USE_FACTORY_PROXY build option to use entry-point in WindowsCodecs.dll rather than CoCreateInstance for the WIC factory --- DirectXTex/DirectXTexUtil.cpp | 40 +++++++++++++++++++++++++++ ScreenGrab/ScreenGrab.cpp | 40 +++++++++++++++++++++++++++ WICTextureLoader/WICTextureLoader.cpp | 40 +++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) diff --git a/DirectXTex/DirectXTexUtil.cpp b/DirectXTex/DirectXTexUtil.cpp index 842bec0..ef96064 100644 --- a/DirectXTex/DirectXTexUtil.cpp +++ b/DirectXTex/DirectXTexUtil.cpp @@ -144,7 +144,47 @@ IWICImagingFactory* _GetWIC() if ( s_Factory ) return s_Factory; +#ifdef WIC_USE_FACTORY_PROXY + HINSTANCE hInst = LoadLibraryEx( TEXT("WindowsCodecs.dll"), nullptr, 0 ); + if ( !hInst ) + return nullptr; + + typedef HRESULT (WINAPI *WICCREATEFACTORY)(UINT, IWICImagingFactory**); + WICCREATEFACTORY pFactory = (WICCREATEFACTORY) GetProcAddress(hInst, "WICCreateImagingFactory_Proxy"); + if ( !pFactory ) + { + FreeLibrary( hInst ); + return nullptr; + } + #if(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE) + HRESULT hr = pFactory( WINCODEC_SDK_VERSION2, &s_Factory ); + if ( SUCCEEDED(hr) ) + { + // WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed + g_WIC2 = true; + } + else + { + hr = pFactory( WINCODEC_SDK_VERSION1, &s_Factory ); + if ( FAILED(hr) ) + { + FreeLibrary( hInst ); + s_Factory = nullptr; + return nullptr; + } + } +#else + HRESULT hr = pFactory( WINCODEC_SDK_VERSION, &s_Factory ); + if ( FAILED(hr) ) + { + FreeLibrary( hInst ); + s_Factory = nullptr; + return nullptr; + } +#endif + +#elif(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE) HRESULT hr = CoCreateInstance( CLSID_WICImagingFactory2, nullptr, diff --git a/ScreenGrab/ScreenGrab.cpp b/ScreenGrab/ScreenGrab.cpp index 4fcd7f9..4facc8e 100644 --- a/ScreenGrab/ScreenGrab.cpp +++ b/ScreenGrab/ScreenGrab.cpp @@ -633,7 +633,47 @@ static IWICImagingFactory* _GetWIC() if ( s_Factory ) return s_Factory; +#ifdef WIC_USE_FACTORY_PROXY + HINSTANCE hInst = LoadLibraryEx( TEXT("WindowsCodecs.dll"), nullptr, 0 ); + if ( !hInst ) + return nullptr; + + typedef HRESULT (WINAPI *WICCREATEFACTORY)(UINT, IWICImagingFactory**); + WICCREATEFACTORY pFactory = (WICCREATEFACTORY) GetProcAddress(hInst, "WICCreateImagingFactory_Proxy"); + if ( !pFactory ) + { + FreeLibrary( hInst ); + return nullptr; + } + #if(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE) + HRESULT hr = pFactory( WINCODEC_SDK_VERSION2, &s_Factory ); + if ( SUCCEEDED(hr) ) + { + // WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed + g_WIC2 = true; + } + else + { + hr = pFactory( WINCODEC_SDK_VERSION1, &s_Factory ); + if ( FAILED(hr) ) + { + FreeLibrary( hInst ); + s_Factory = nullptr; + return nullptr; + } + } +#else + HRESULT hr = pFactory( WINCODEC_SDK_VERSION, &s_Factory ); + if ( FAILED(hr) ) + { + FreeLibrary( hInst ); + s_Factory = nullptr; + return nullptr; + } +#endif + +#elif(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE) HRESULT hr = CoCreateInstance( CLSID_WICImagingFactory2, nullptr, diff --git a/WICTextureLoader/WICTextureLoader.cpp b/WICTextureLoader/WICTextureLoader.cpp index 9e6c22b..74d3bf7 100644 --- a/WICTextureLoader/WICTextureLoader.cpp +++ b/WICTextureLoader/WICTextureLoader.cpp @@ -217,7 +217,47 @@ static IWICImagingFactory* _GetWIC() if ( s_Factory ) return s_Factory; +#ifdef WIC_USE_FACTORY_PROXY + HINSTANCE hInst = LoadLibraryEx( TEXT("WindowsCodecs.dll"), nullptr, 0 ); + if ( !hInst ) + return nullptr; + + typedef HRESULT (WINAPI *WICCREATEFACTORY)(UINT, IWICImagingFactory**); + WICCREATEFACTORY pFactory = (WICCREATEFACTORY) GetProcAddress(hInst, "WICCreateImagingFactory_Proxy"); + if ( !pFactory ) + { + FreeLibrary( hInst ); + return nullptr; + } + #if(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE) + HRESULT hr = pFactory( WINCODEC_SDK_VERSION2, &s_Factory ); + if ( SUCCEEDED(hr) ) + { + // WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed + g_WIC2 = true; + } + else + { + hr = pFactory( WINCODEC_SDK_VERSION1, &s_Factory ); + if ( FAILED(hr) ) + { + FreeLibrary( hInst ); + s_Factory = nullptr; + return nullptr; + } + } +#else + HRESULT hr = pFactory( WINCODEC_SDK_VERSION, &s_Factory ); + if ( FAILED(hr) ) + { + FreeLibrary( hInst ); + s_Factory = nullptr; + return nullptr; + } +#endif + +#elif(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE) HRESULT hr = CoCreateInstance( CLSID_WICImagingFactory2, nullptr,