ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs
(Generate patch)

Comparing trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs (file contents):
Revision 283 by william, Sun Jun 3 16:51:35 2012 UTC vs.
Revision 284 by william, Tue Jun 5 01:50:38 2012 UTC

--- trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/06/05 01:50:13	283
+++ trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/06/05 01:50:38	284
@@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
 using RomCheater.Logging;
 using System.IO;
 using Sojaner.MemoryScanner.MemoryProviers;
+using Microsoft.Win32.SafeHandles;
 
 namespace Sojaner.MemoryScanner
 {
@@ -37,7 +38,7 @@ namespace Sojaner.MemoryScanner
         }
 
         private Process m_ReadProcess = null;
-
+        
         private static IntPtr m_hProcess = IntPtr.Zero;
 
         public void OpenProcess()
@@ -68,12 +69,16 @@ namespace Sojaner.MemoryScanner
         {
             try
             {
-                int iRetValue;
-                iRetValue = ProcessMemoryReaderApi.CloseHandle(m_hProcess);
-                if (iRetValue == 0)
-                {
-                    throw new Exception("CloseHandle failed");
-                }
+                SafeWaitHandle handle = new SafeWaitHandle(m_hProcess, true);
+                if (handle.IsClosed) { return; }                
+                handle.Close();
+                //string stack_trace = System.Environment.StackTrace;
+                //int iRetValue;
+                //iRetValue = ProcessMemoryReaderApi.CloseHandle(m_hProcess);
+                //if (iRetValue == 0)
+                //{
+                //    throw new Exception("CloseHandle failed");
+                //}
             }
             catch (SEHException ex)
             {