From c50a4038e3c3a13e3d493c432017d371d4916ce6 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Sat, 8 Jan 2005 17:44:46 +0000
Subject: [PATCH] implemented wxIsDebuggerRunning() for Win32

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31296 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/function.tex |  7 +++----
 include/wx/debug.h         | 12 +++++++-----
 src/msw/utils.cpp          | 19 +++++++++++++++++++
 3 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex
index 9ede1fbaa6..852ce33397 100644
--- a/docs/latex/wx/function.tex
+++ b/docs/latex/wx/function.tex
@@ -4213,11 +4213,10 @@ In release mode this function does nothing.
 
 \func{bool}{wxIsDebuggerRunning}{\void}
 
-Returns {\tt true} if the program is running under debugger, {\tt false} 
-otherwise.
+Returns \true if the program is running under debugger, \false otherwise.
 
-Please note that this function is currently only implemented for Mac builds
-using CodeWarrior and always returns {\tt false} elsewhere.
+Please note that this function is currently only implemented for Win32 and Mac
+builds using CodeWarrior and always returns \false elsewhere.
 
 
 
diff --git a/include/wx/debug.h b/include/wx/debug.h
index 5f1e1559bb..f0ca48d9fc 100644
--- a/include/wx/debug.h
+++ b/include/wx/debug.h
@@ -233,12 +233,14 @@
 /*  other miscellaneous debugger-related functions */
 /*  ---------------------------------------------------------------------------- */
 
-/*  return true if we're running under debugger */
-/*  */
-/*  currently this only really works under Mac in CodeWarrior builds, it always */
-/*  returns false otherwise */
+/*
+    Return true if we're running under debugger.
+
+    Currently this only really works under Win32 and Mac in CodeWarrior builds,
+    it always returns false in other cases.
+ */
 #ifdef __cplusplus
-    #ifdef __WXMAC__
+    #if defined(__WXMAC__) || defined(__WXMSW__)
         extern bool WXDLLIMPEXP_BASE wxIsDebuggerRunning();
     #else /*  !Mac */
         inline bool wxIsDebuggerRunning() { return false; }
diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp
index f174df6fd3..71f5e6521e 100644
--- a/src/msw/utils.cpp
+++ b/src/msw/utils.cpp
@@ -1036,6 +1036,25 @@ void wxBell()
     ::MessageBeep((UINT)-1);        // default sound
 }
 
+bool wxIsDebuggerRunning()
+{
+    // IsDebuggerPresent() is not available under Win95, so load it dynamically
+    wxDynamicLibrary dll(_T("kernel32.dll"), wxDL_VERBATIM);
+
+    typedef BOOL (WINAPI *IsDebuggerPresent_t)();
+    if ( !dll.HasSymbol(_T("IsDebuggerPresent")) )
+    {
+        // no way to know, assume no
+        return false;
+    }
+
+    return (*(IsDebuggerPresent_t)dll.GetSymbol(_T("IsDebuggerPresent")))() != 0;
+}
+
+// ----------------------------------------------------------------------------
+// OS version
+// ----------------------------------------------------------------------------
+
 wxString wxGetOsDescription()
 {
     wxString str;
-- 
2.50.0

