The code below is a runtime dubugger for windows that acts on the bare minimum without including windows.h itself. I know this doesn't answer the question directly but what you need to define specifically in order for your code to work is an architecture definition (preprocessor stuff), and <errhandlingapi.h>
, and <windef.h>
. I'm not completely sure what else so refer to my example below:
My code:
#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_IX86)
#define _X86_
#if !defined(_CHPE_X86_ARM64_) && defined(_M_HYBRID)
#define _CHPE_X86_ARM64_
#endif
#endif
#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_AMD64)
#define _AMD64_
#endif
#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_ARM)
#define _ARM_
#endif
#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_ARM64)
#define _ARM64_
#endif
#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_M68K)
#define _68K_
#endif
#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_MPPC)
#define _MPPC_
#endif
#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_M_IX86) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_IA64)
#if !defined(_IA64_)
#define _IA64_
#endif /* !_IA64_ */
#endif
#ifndef _MAC
#if defined(_68K_) || defined(_MPPC_)
#define _MAC
#endif
#endif
#include <string>
#include <windef.h>
#include <WinUser.h>
#include <WinNls.h>
#include <errhandlingapi.h>
#include <processthreadsapi.h>
#include <WinBase.h>
__pragma (comment(lib, "User32"));
namespace Microsoft {
void __stdcall rt_assert(const bool test, const wchar_t* FunctionName)
{
if (test) return;
// Retrieve the system error message for the last-error code
unsigned __int32 ERROR_ID = GetLastError();
void* MsgBuffer;
LCID lcid; //language id
GetLocaleInfoEx(L"en-US", LOCALE_RETURN_NUMBER | LOCALE_ILANGUAGE, (wchar_t*)&lcid, sizeof(lcid));
//get error message and attach it to Msgbuffer
FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, ERROR_ID, lcid, (wchar_t*)&MsgBuffer, 0, NULL);
//concatonate string to DisplayBuffer
const std::wstring DisplayBuffer = (static_cast<std::wstring>(FunctionName) + L" failed with error " + std::to_wstring(ERROR_ID) + L": " + static_cast<const wchar_t*>(MsgBuffer)).c_str();
// Display the error message and exit the process
if (IsDebuggerPresent())
{
OutputDebugStringW(DisplayBuffer.c_str());
}
else
{
MessageBoxExW(NULL, DisplayBuffer.c_str(), L"Error", MB_ICONERROR | MB_OK, static_cast<unsigned __int16>(lcid));
}
ExitProcess(ERROR_ID);
}
}