From 895c5766bc5b55931f07d0d9e075e222583d7147 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Wed, 13 May 2020 09:06:48 +0200 Subject: [PATCH] Add some workarounds to not include windows.h on _WIN32 platform. --- VulkanHppGenerator.cpp | 53 ++++++++++++++++++++++++------------------ vulkan/vulkan.hpp | 33 +++++++++++++++----------- 2 files changed, 50 insertions(+), 36 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 024c5bf..d5c5fcd 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1404,6 +1404,15 @@ void VulkanHppGenerator::appendDispatchLoaderDynamic( std::string & str ) { str += R"( #if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL +# if defined( _WIN32 ) + namespace detail + { + extern "C" __declspec( dllimport ) void * __stdcall LoadLibraryA( char const * lpLibFileName ); + extern "C" __declspec( dllimport ) int __stdcall FreeLibrary( void * hLibModule ); + extern "C" __declspec( dllimport ) void * __stdcall GetProcAddress( void * hModule, char const * lpProcName ); + } // namespace detail +# endif + class DynamicLoader { public: @@ -1418,9 +1427,9 @@ void VulkanHppGenerator::appendDispatchLoaderDynamic( std::string & str ) # if defined( __linux__ ) || defined( __APPLE__ ) m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL ); # elif defined( _WIN32 ) - m_library = LoadLibrary( vulkanLibraryName.c_str() ); + m_library = detail::LoadLibraryA( vulkanLibraryName.c_str() ); # else - VULKAN_HPP_ASSERT( false && "unsupported platform" ); +# error unsupported platform # endif } else @@ -1434,9 +1443,9 @@ void VulkanHppGenerator::appendDispatchLoaderDynamic( std::string & str ) # elif defined( __APPLE__ ) m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL ); # elif defined( _WIN32 ) - m_library = LoadLibrary( TEXT( "vulkan-1.dll" ) ); + m_library = detail::LoadLibraryA( "vulkan-1.dll" ); # else - VULKAN_HPP_ASSERT( false && "unsupported platform" ); +# error unsupported platform # endif } @@ -1472,35 +1481,37 @@ void VulkanHppGenerator::appendDispatchLoaderDynamic( std::string & str ) { if ( m_library ) { -#if defined(__linux__) || defined(__APPLE__) +# if defined( __linux__ ) || defined( __APPLE__ ) dlclose( m_library ); -#elif defined(_WIN32) - FreeLibrary( m_library ); -#endif +# elif defined( _WIN32 ) + detail::FreeLibrary( m_library ); +# else +# error unsupported platform +# endif } } template T getProcAddress( const char* function ) const VULKAN_HPP_NOEXCEPT { -#if defined(__linux__) || defined(__APPLE__) +# if defined( __linux__ ) || defined( __APPLE__ ) return (T)dlsym( m_library, function ); -#elif defined(_WIN32) - return (T)GetProcAddress( m_library, function ); -#endif +# elif defined( _WIN32 ) + return (T)detail::GetProcAddress( m_library, function ); +# else +# error unsupported platform +# endif } bool success() const VULKAN_HPP_NOEXCEPT { return m_success; } private: bool m_success; -#if defined(__linux__) || defined(__APPLE__) - void *m_library; -#elif defined(_WIN32) - HMODULE m_library; -#else -#error unsupported platform -#endif +# if defined( __linux__ ) || defined( __APPLE__ ) || defined( _WIN32 ) + void * m_library; +# else +# error unsupported platform +# endif }; #endif @@ -7811,10 +7822,6 @@ int main( int argc, char ** argv ) # if defined(__linux__) || defined(__APPLE__) # include # endif - -# if defined(_WIN32) -# include -# endif #endif #if 201711 <= __cpp_impl_three_way_comparison diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 4740c04..e955a8d 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -69,10 +69,6 @@ # if defined( __linux__ ) || defined( __APPLE__ ) # include # endif - -# if defined( _WIN32 ) -# include -# endif #endif #if 201711 <= __cpp_impl_three_way_comparison @@ -96704,6 +96700,15 @@ namespace VULKAN_HPP_NAMESPACE }; #if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL +# if defined( _WIN32 ) + namespace detail + { + extern "C" __declspec( dllimport ) void * __stdcall LoadLibraryA( char const * lpLibFileName ); + extern "C" __declspec( dllimport ) int __stdcall FreeLibrary( void * hLibModule ); + extern "C" __declspec( dllimport ) void * __stdcall GetProcAddress( void * hModule, char const * lpProcName ); + } // namespace detail +# endif + class DynamicLoader { public: @@ -96718,9 +96723,9 @@ namespace VULKAN_HPP_NAMESPACE # if defined( __linux__ ) || defined( __APPLE__ ) m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL ); # elif defined( _WIN32 ) - m_library = LoadLibrary( vulkanLibraryName.c_str() ); + m_library = detail::LoadLibraryA( vulkanLibraryName.c_str() ); # else - VULKAN_HPP_ASSERT( false && "unsupported platform" ); +# error unsupported platform # endif } else @@ -96734,9 +96739,9 @@ namespace VULKAN_HPP_NAMESPACE # elif defined( __APPLE__ ) m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL ); # elif defined( _WIN32 ) - m_library = LoadLibrary( TEXT( "vulkan-1.dll" ) ); + m_library = detail::LoadLibraryA( "vulkan-1.dll" ); # else - VULKAN_HPP_ASSERT( false && "unsupported platform" ); +# error unsupported platform # endif } @@ -96776,7 +96781,9 @@ namespace VULKAN_HPP_NAMESPACE # if defined( __linux__ ) || defined( __APPLE__ ) dlclose( m_library ); # elif defined( _WIN32 ) - FreeLibrary( m_library ); + detail::FreeLibrary( m_library ); +# else +# error unsupported platform # endif } } @@ -96787,7 +96794,9 @@ namespace VULKAN_HPP_NAMESPACE # if defined( __linux__ ) || defined( __APPLE__ ) return (T)dlsym( m_library, function ); # elif defined( _WIN32 ) - return (T)GetProcAddress( m_library, function ); + return (T)detail::GetProcAddress( m_library, function ); +# else +# error unsupported platform # endif } @@ -96798,10 +96807,8 @@ namespace VULKAN_HPP_NAMESPACE private: bool m_success; -# if defined( __linux__ ) || defined( __APPLE__ ) +# if defined( __linux__ ) || defined( __APPLE__ ) || defined( _WIN32 ) void * m_library; -# elif defined( _WIN32 ) - HMODULE m_library; # else # error unsupported platform # endif