浏览代码

Issue #85 - Get rid of the deprecated FileHandle API (#167)

Oleg Nenashev 8 年之前
父节点
当前提交
ab51b50d85
共有 2 个文件被更改,包括 6 次插入5 次删除
  1. 1 1
      src/Core/ServiceWrapper/Main.cs
  2. 5 4
      src/Core/WinSWCore/Native/Kernel32.cs

+ 1 - 1
src/Core/ServiceWrapper/Main.cs

@@ -555,7 +555,7 @@ namespace winsw
                     Console.SetOut(w);
                     Console.SetError(w);
 
-                    var handle = f.Handle;
+                    var handle = f.SafeFileHandle;
                     Kernel32.SetStdHandle(-11, handle); // set stdout
                     Kernel32.SetStdHandle(-12, handle); // set stder
 

+ 5 - 4
src/Core/WinSWCore/Native/Kernel32.cs

@@ -1,4 +1,5 @@
-using System;
+using Microsoft.Win32.SafeHandles;
+using System;
 using System.Runtime.InteropServices;
 
 namespace winsw.Native
@@ -7,9 +8,9 @@ namespace winsw.Native
     /// kernel32.dll P/Invoke wrappers
     /// </summary>
     public class Kernel32
-    {
-        [DllImport("Kernel32.dll", SetLastError = true)]
-        public static extern int SetStdHandle(int device, IntPtr handle);
+    {        
+        [DllImport("kernel32.dll", SetLastError = true)]
+        public static extern bool SetStdHandle(int nStdHandle, SafeFileHandle handle);
 
         [DllImport("kernel32.dll", SetLastError = true)]
         public static extern bool CreateProcess(string lpApplicationName,