throw std::runtime_error((MESSAGE)); \
} \
while(0)
+
+#define MUTILS_THROW_FMT(MESSAGE, ...) do \
+{ \
+ char _message[256]; \
+ _snprintf_s(_message, 256, _TRUNCATE, (MESSAGE), __VA_ARGS__); \
+ throw std::runtime_error(_message); \
+} \
+while(0)
///////////////////////////////////////////////////////////////////////////////
-#define MUTILS_DELETE(PTR) do \
-{ \
- if((PTR)) \
- { \
- delete (PTR); \
- (PTR) = NULL; \
- } \
-} \
-while(0)
-
-#define MUTILS_DELETE_ARRAY(PTR) do \
-{ \
- if((PTR)) \
- { \
- delete [] (PTR); \
- (PTR) = NULL; \
- } \
-} \
-while(0)
+//Delete helper
+#define MUTILS_DELETE(PTR) do { if((PTR)) { delete (PTR); (PTR) = NULL; } } while(0)
+#define MUTILS_DELETE_ARRAY(PTR) do { if((PTR)) { delete [] (PTR); (PTR) = NULL; } } while(0)
+
+//Zero memory
+#define MUTILS_ZERO_MEMORY(PTR) memset(&(PTR), 0, sizeof((PTR)))
//String conversion macros
#define MUTILS_WCHR(STR) (reinterpret_cast<const wchar_t*>((STR).utf16()))
//Message handler
MUTILS_API bool handle_os_message(const void *const message, long *result);
+ //Sleep
+ MUTILS_API void sleep_ms(const size_t &duration);
+
+ //Check if debugger is present
+ MUTILS_API void check_debugger(void);
+
//Error handling
MUTILS_API void fatal_exit(const wchar_t* const errorMessage);
}
}
///////////////////////////////////////////////////////////////////////////////
+// SLEEP
+///////////////////////////////////////////////////////////////////////////////
+
+void MUtils::OS::sleep_ms(const size_t &duration)
+{
+ Sleep((DWORD) duration);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// DEBUGGER CHECK
+///////////////////////////////////////////////////////////////////////////////
+
+#if (!(MUTILS_DEBUG))
+static __forceinline bool is_debugger_present(void)
+{
+ __try
+ {
+ CloseHandle((HANDLE)((DWORD_PTR)-3));
+ }
+ __except(1)
+ {
+ return true;
+ }
+
+ BOOL bHaveDebugger = FALSE;
+ if(CheckRemoteDebuggerPresent(GetCurrentProcess(), &bHaveDebugger))
+ {
+ if(bHaveDebugger) return true;
+ }
+
+ return IsDebuggerPresent();
+}
+static __forceinline bool check_debugger_helper(void)
+{
+ if(is_debugger_present())
+ {
+ MUtils::OS::fatal_exit(L"Not a debug build. Please unload debugger and try again!");
+ return true;
+ }
+ return false;
+}
+#else
+#define check_debugger_helper() (false)
+#endif
+
+void MUtils::OS::check_debugger(void)
+{
+ check_debugger_helper();
+}
+
+static volatile bool g_debug_check = check_debugger_helper();
+
+///////////////////////////////////////////////////////////////////////////////
// FATAL EXIT
///////////////////////////////////////////////////////////////////////////////
__try
{
MUtils::ErrorHandler::initialize();
+ MUtils::OS::check_debugger();
iResult = startup_helper(argc, argv, entry_point);
}
__except(1)
}
#else //_MSCVER
MUtils::ErrorHandler::initialize();
+ MUtils::OS::check_debugger();
iResult = startup_helper(argc, argv, entry_point);
#endif //_MSCVER
#endif //MUTILS_DEBUG