Skip to content

Commit

Permalink
Added a workaround for CryptReleaseContext in Windows 2000
Browse files Browse the repository at this point in the history
CryptReleaseContext is declared differently in MS Windows SDK 6.0A and
later when targeting Windows versions older than XP. This is not the case
in MinGW and MinGW-w64 and MSVC shipped with their own Windows SDK.

Also added BOOST_WINAPI_DEFINE_VERSION_MACROS config macro which allows
Boost.WinAPI to define Windows SDK version macros even when it is not
configured to include windows.h. This can help to ensure that the user
targets the same Windows version as Boost.
  • Loading branch information
Lastique committed Jan 16, 2017
1 parent f2f956c commit d1ce3b2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 7 additions & 1 deletion include/boost/detail/winapi/config.hpp
Expand Up @@ -54,14 +54,20 @@
#endif
#endif

#if defined(BOOST_USE_WINDOWS_H)
#define BOOST_DETAIL_WINAPI_MAKE_NTDDI_VERSION2(x) x##0000
#define BOOST_DETAIL_WINAPI_MAKE_NTDDI_VERSION(x) BOOST_DETAIL_WINAPI_MAKE_NTDDI_VERSION2(x)

#if defined(BOOST_USE_WINDOWS_H) || defined(BOOST_WINAPI_DEFINE_VERSION_MACROS)
// We have to define the version macros so that windows.h provides the necessary symbols
#if !defined(_WIN32_WINNT)
#define _WIN32_WINNT BOOST_USE_WINAPI_VERSION
#endif
#if !defined(WINVER)
#define WINVER BOOST_USE_WINAPI_VERSION
#endif
#if !defined(NTDDI_VERSION)
#define NTDDI_VERSION BOOST_DETAIL_WINAPI_MAKE_NTDDI_VERSION(BOOST_USE_WINAPI_VERSION)
#endif
#endif

#include <boost/config.hpp>
Expand Down
19 changes: 18 additions & 1 deletion include/boost/detail/winapi/crypt.hpp
Expand Up @@ -98,10 +98,23 @@ CryptGenRandom(
boost::detail::winapi::DWORD_ dwLen,
boost::detail::winapi::BYTE_ *pbBuffer);

#if defined(_MSC_VER) && (_MSC_VER+0) >= 1500 &&\
(\
(defined(NTDDI_VERSION) && (NTDDI_VERSION+0) < BOOST_DETAIL_WINAPI_MAKE_NTDDI_VERSION(BOOST_WINAPI_VERSION_WINXP)) ||\
(!defined(NTDDI_VERSION) && BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_WINXP)\
)
// Standalone MS Windows SDK 6.0A and later provide a different declaration of CryptReleaseContext for Windows 2000 and older.
// This is not the case for (a) MinGW and MinGW-w64 and (b) MSVC 7.1 and 8, which are shipped with their own Windows SDK.
BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI
CryptReleaseContext(
boost::detail::winapi::HCRYPTPROV_ hProv,
boost::detail::winapi::ULONG_PTR_ dwFlags);
#else
BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI
CryptReleaseContext(
boost::detail::winapi::HCRYPTPROV_ hProv,
boost::detail::winapi::DWORD_ dwFlags);
#endif
}
#endif // !defined( BOOST_USE_WINDOWS_H )

Expand Down Expand Up @@ -140,7 +153,6 @@ using ::CryptAcquireContextA;
using ::CryptEnumProvidersW;
using ::CryptAcquireContextW;
using ::CryptGenRandom;
using ::CryptReleaseContext;

#if !defined( BOOST_NO_ANSI_APIS )
BOOST_FORCEINLINE BOOL_ crypt_enum_providers(
Expand Down Expand Up @@ -186,6 +198,11 @@ BOOST_FORCEINLINE BOOL_ crypt_acquire_context(
return ::CryptAcquireContextW(phProv, szContainer, szProvider, dwProvType, dwFlags);
}

BOOST_FORCEINLINE BOOL_ CryptReleaseContext(HCRYPTPROV_ hProv, DWORD_ dwFlags)
{
return ::CryptReleaseContext(hProv, dwFlags);
}

}
}
}
Expand Down

0 comments on commit d1ce3b2

Please sign in to comment.