Skip to content

Commit

Permalink
Fix issue #32 Mingw build support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ned14 committed Mar 12, 2024
1 parent 41e7d25 commit 18c0deb
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 52 deletions.
2 changes: 2 additions & 0 deletions include/status-code/com_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Distributed under the Boost Software License, Version 1.0.
#include "win32_code.hpp"

#ifndef STANDARDESE_IS_IN_THE_HOUSE
#include <stdio.h> // needed by mingw for comdef.h to work

#include <comdef.h>
#endif

Expand Down
20 changes: 14 additions & 6 deletions include/status-code/nt_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ SYSTEM_ERROR2_NAMESPACE_BEGIN
//! \exclude
namespace win32
{
// A Win32 NTSTATUS
using NTSTATUS = long;
// A Win32 HMODULE
using HMODULE = void *;
// Used to retrieve where the NTDLL DLL is mapped into memory
extern HMODULE __stdcall GetModuleHandleW(const wchar_t *lpModuleName);
#ifdef __MINGW32__
extern "C"
{
#endif
// A Win32 NTSTATUS
using NTSTATUS = long;
// A Win32 HMODULE
using HMODULE = void *;
// Used to retrieve where the NTDLL DLL is mapped into memory
extern HMODULE __stdcall GetModuleHandleW(const wchar_t *lpModuleName);
#ifdef __MINGW32__
}
#else
#pragma comment(lib, "kernel32.lib")
#if(defined(__x86_64__) || defined(_M_X64)) || (defined(__aarch64__) || defined(_M_ARM64))
#pragma comment(linker, "/alternatename:?GetModuleHandleW@win32@system_error2@@YAPEAXPEB_W@Z=GetModuleHandleW")
Expand All @@ -52,6 +59,7 @@ namespace win32
#else
#error Unknown architecture
#endif
#endif
} // namespace win32

class _nt_code_domain;
Expand Down
31 changes: 20 additions & 11 deletions include/status-code/win32_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,23 @@ SYSTEM_ERROR2_NAMESPACE_BEGIN
//! \exclude
namespace win32
{
// A Win32 DWORD
using DWORD = unsigned long;
// Used to retrieve the current Win32 error code
extern DWORD __stdcall GetLastError();
// Used to retrieve a locale-specific message string for some error code
extern DWORD __stdcall FormatMessageW(DWORD dwFlags, const void *lpSource, DWORD dwMessageId, DWORD dwLanguageId, wchar_t *lpBuffer, DWORD nSize,
void /*va_list*/ *Arguments);
// Converts UTF-16 message string to UTF-8
extern int __stdcall WideCharToMultiByte(unsigned int CodePage, DWORD dwFlags, const wchar_t *lpWideCharStr, int cchWideChar, char *lpMultiByteStr,
int cbMultiByte, const char *lpDefaultChar, int *lpUsedDefaultChar);
#ifdef __MINGW32__
extern "C"
{
#endif
// A Win32 DWORD
using DWORD = unsigned long;
// Used to retrieve the current Win32 error code
extern DWORD __stdcall GetLastError();
// Used to retrieve a locale-specific message string for some error code
extern DWORD __stdcall FormatMessageW(DWORD dwFlags, const void *lpSource, DWORD dwMessageId, DWORD dwLanguageId, wchar_t *lpBuffer, DWORD nSize,
void /*va_list*/ *Arguments);
// Converts UTF-16 message string to UTF-8
extern int __stdcall WideCharToMultiByte(unsigned int CodePage, DWORD dwFlags, const wchar_t *lpWideCharStr, int cchWideChar, char *lpMultiByteStr,
int cbMultiByte, const char *lpDefaultChar, int *lpUsedDefaultChar);
#ifdef __MINGW32__
}
#else
#pragma comment(lib, "kernel32.lib")
#if(defined(__x86_64__) || defined(_M_X64)) || (defined(__aarch64__) || defined(_M_ARM64))
#pragma comment(linker, "/alternatename:?GetLastError@win32@system_error2@@YAKXZ=GetLastError")
Expand All @@ -62,6 +69,7 @@ namespace win32
#else
#error Unknown architecture
#endif
#endif
} // namespace win32

class _win32_code_domain;
Expand Down Expand Up @@ -213,7 +221,8 @@ class _win32_code_domain : public status_code_domain
}
#endif
};
//! (Windows only) A constexpr source variable for the win32 code domain, which is that of `GetLastError()` (Windows). Returned by `_win32_code_domain::get()`.
//! (Windows only) A constexpr source variable for the win32 code domain, which is that of `GetLastError()` (Windows). Returned by
//! `_win32_code_domain::get()`.
constexpr _win32_code_domain win32_code_domain;
inline constexpr const _win32_code_domain &_win32_code_domain::get()
{
Expand Down
18 changes: 9 additions & 9 deletions single-header/system_error2-nowindows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2470,7 +2470,7 @@ template <class DomainType> class errored_status_code : public status_code<Domai
//! Always false (including at compile time), as errored status codes are never successful.
constexpr bool success() const noexcept { return false; }
//! Return a const reference to the `value_type`.
constexpr const value_type &value() const &noexcept { return this->_value; }
constexpr const value_type &value() const & noexcept { return this->_value; }
};
namespace traits
{
Expand Down Expand Up @@ -2580,8 +2580,8 @@ template <class ErasedType> class errored_status_code<detail::erased<ErasedType>
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
//! Explicit copy construction from an unknown status code. Note that this will be empty if its value type is not trivially copyable or would not fit into our
//! storage or the source domain's `_do_erased_copy()` refused the copy.
explicit errored_status_code(const status_code<void> &v) // NOLINT
: _base(v)
explicit errored_status_code(in_place_t _, const status_code<void> &v) // NOLINT
: _base(_, v)
{
_check();
}
Expand Down Expand Up @@ -2952,18 +2952,18 @@ static_assert(traits::is_move_bitcopying<system_code>::value, "system_code is no
SYSTEM_ERROR2_NAMESPACE_END
#endif
SYSTEM_ERROR2_NAMESPACE_BEGIN
/*! An errored `system_code` which is always a failure. The closest equivalent to
`std::error_code`, except it cannot be null and cannot be modified.
/*! An errored `system_code` which must be a failure upon copy or move or
non-default construction. The closest equivalent to `std::error_code`, except
it cannot be modified.
This refines `system_code` into an `error` object meeting the requirements of
[P0709 Zero-overhead deterministic exceptions](https://wg21.link/P0709).
Differences from `system_code`:
- Always a failure (this is checked at construction, and if not the case,
the program is terminated as this is a logic error)
- No default construction.
- No empty state possible.
- Almost always a failure (this is checked at copy or move and non-default
construction, and if not the case, the program is terminated as this is a logic
error)
- Is immutable.
As with `system_code`, it remains guaranteed to be two CPU registers in size,
Expand Down
69 changes: 43 additions & 26 deletions single-header/system_error2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2470,7 +2470,7 @@ template <class DomainType> class errored_status_code : public status_code<Domai
//! Always false (including at compile time), as errored status codes are never successful.
constexpr bool success() const noexcept { return false; }
//! Return a const reference to the `value_type`.
constexpr const value_type &value() const &noexcept { return this->_value; }
constexpr const value_type &value() const & noexcept { return this->_value; }
};
namespace traits
{
Expand Down Expand Up @@ -2580,8 +2580,8 @@ template <class ErasedType> class errored_status_code<detail::erased<ErasedType>
#if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || 0L
//! Explicit copy construction from an unknown status code. Note that this will be empty if its value type is not trivially copyable or would not fit into our
//! storage or the source domain's `_do_erased_copy()` refused the copy.
explicit errored_status_code(const status_code<void> &v) // NOLINT
: _base(v)
explicit errored_status_code(in_place_t _, const status_code<void> &v) // NOLINT
: _base(_, v)
{
_check();
}
Expand Down Expand Up @@ -2992,16 +2992,23 @@ SYSTEM_ERROR2_NAMESPACE_BEGIN
//! \exclude
namespace win32
{
// A Win32 DWORD
using DWORD = unsigned long;
// Used to retrieve the current Win32 error code
extern DWORD __stdcall GetLastError();
// Used to retrieve a locale-specific message string for some error code
extern DWORD __stdcall FormatMessageW(DWORD dwFlags, const void *lpSource, DWORD dwMessageId, DWORD dwLanguageId, wchar_t *lpBuffer, DWORD nSize,
void /*va_list*/ *Arguments);
// Converts UTF-16 message string to UTF-8
extern int __stdcall WideCharToMultiByte(unsigned int CodePage, DWORD dwFlags, const wchar_t *lpWideCharStr, int cchWideChar, char *lpMultiByteStr,
int cbMultiByte, const char *lpDefaultChar, int *lpUsedDefaultChar);
#ifdef __MINGW32__
extern "C"
{
#endif
// A Win32 DWORD
using DWORD = unsigned long;
// Used to retrieve the current Win32 error code
extern DWORD __stdcall GetLastError();
// Used to retrieve a locale-specific message string for some error code
extern DWORD __stdcall FormatMessageW(DWORD dwFlags, const void *lpSource, DWORD dwMessageId, DWORD dwLanguageId, wchar_t *lpBuffer, DWORD nSize,
void /*va_list*/ *Arguments);
// Converts UTF-16 message string to UTF-8
extern int __stdcall WideCharToMultiByte(unsigned int CodePage, DWORD dwFlags, const wchar_t *lpWideCharStr, int cchWideChar, char *lpMultiByteStr,
int cbMultiByte, const char *lpDefaultChar, int *lpUsedDefaultChar);
#ifdef __MINGW32__
}
#else
#pragma comment(lib, "kernel32.lib")
#if (defined(__x86_64__) || defined(_M_X64)) || (defined(__aarch64__) || defined(_M_ARM64))
#pragma comment(linker, "/alternatename:?GetLastError@win32@system_error2@@YAKXZ=GetLastError")
Expand All @@ -3018,6 +3025,7 @@ namespace win32
#else
#error Unknown architecture
#endif
#endif
} // namespace win32
class _win32_code_domain;
class _com_code_domain;
Expand Down Expand Up @@ -3233,7 +3241,8 @@ case 0x2751: return EHOSTUNREACH;
}
#endif
};
//! (Windows only) A constexpr source variable for the win32 code domain, which is that of `GetLastError()` (Windows). Returned by `_win32_code_domain::get()`.
//! (Windows only) A constexpr source variable for the win32 code domain, which is that of `GetLastError()` (Windows). Returned by
//! `_win32_code_domain::get()`.
constexpr _win32_code_domain win32_code_domain;
inline constexpr const _win32_code_domain &_win32_code_domain::get()
{
Expand All @@ -3252,12 +3261,19 @@ SYSTEM_ERROR2_NAMESPACE_BEGIN
//! \exclude
namespace win32
{
// A Win32 NTSTATUS
using NTSTATUS = long;
// A Win32 HMODULE
using HMODULE = void *;
// Used to retrieve where the NTDLL DLL is mapped into memory
extern HMODULE __stdcall GetModuleHandleW(const wchar_t *lpModuleName);
#ifdef __MINGW32__
extern "C"
{
#endif
// A Win32 NTSTATUS
using NTSTATUS = long;
// A Win32 HMODULE
using HMODULE = void *;
// Used to retrieve where the NTDLL DLL is mapped into memory
extern HMODULE __stdcall GetModuleHandleW(const wchar_t *lpModuleName);
#ifdef __MINGW32__
}
#else
#pragma comment(lib, "kernel32.lib")
#if (defined(__x86_64__) || defined(_M_X64)) || (defined(__aarch64__) || defined(_M_ARM64))
#pragma comment(linker, "/alternatename:?GetModuleHandleW@win32@system_error2@@YAPEAXPEB_W@Z=GetModuleHandleW")
Expand All @@ -3268,6 +3284,7 @@ namespace win32
#else
#error Unknown architecture
#endif
#endif
} // namespace win32
class _nt_code_domain;
//! (Windows only) A NT error code, those returned by NT kernel functions.
Expand Down Expand Up @@ -4570,18 +4587,18 @@ static_assert(traits::is_move_bitcopying<system_code>::value, "system_code is no
SYSTEM_ERROR2_NAMESPACE_END
#endif
SYSTEM_ERROR2_NAMESPACE_BEGIN
/*! An errored `system_code` which is always a failure. The closest equivalent to
`std::error_code`, except it cannot be null and cannot be modified.
/*! An errored `system_code` which must be a failure upon copy or move or
non-default construction. The closest equivalent to `std::error_code`, except
it cannot be modified.
This refines `system_code` into an `error` object meeting the requirements of
[P0709 Zero-overhead deterministic exceptions](https://wg21.link/P0709).
Differences from `system_code`:
- Always a failure (this is checked at construction, and if not the case,
the program is terminated as this is a logic error)
- No default construction.
- No empty state possible.
- Almost always a failure (this is checked at copy or move and non-default
construction, and if not the case, the program is terminated as this is a logic
error)
- Is immutable.
As with `system_code`, it remains guaranteed to be two CPU registers in size,
Expand Down

0 comments on commit 18c0deb

Please sign in to comment.