From ab51b50d855956ad11fc6eabdb1e592ec0c4e830 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Thu, 22 Dec 2016 23:40:44 +0100 Subject: [PATCH] Issue #85 - Get rid of the deprecated FileHandle API (#167) --- src/Core/ServiceWrapper/Main.cs | 2 +- src/Core/WinSWCore/Native/Kernel32.cs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Core/ServiceWrapper/Main.cs b/src/Core/ServiceWrapper/Main.cs index c11a99b..b4cdb08 100644 --- a/src/Core/ServiceWrapper/Main.cs +++ b/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 diff --git a/src/Core/WinSWCore/Native/Kernel32.cs b/src/Core/WinSWCore/Native/Kernel32.cs index 3d57a9a..c91ceb8 100755 --- a/src/Core/WinSWCore/Native/Kernel32.cs +++ b/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 /// 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,