This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Win32.cs
61 lines (46 loc) · 2.64 KB
/
Win32.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Runtime.InteropServices;
static class Win32 {
const string kernel32 = "kernel32.dll";
[DllImport(kernel32, SetLastError = true)]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport(kernel32, SetLastError = true)]
public static extern bool CloseHandle(IntPtr hObject);
[DllImport(kernel32, SetLastError = true)]
public static extern bool CreatePipe(out IntPtr hReadPipe, out IntPtr hWritePipe, SECURITY_ATTRIBUTES lpPipeAttributes, int nSize);
[DllImport(kernel32, SetLastError = true)]
public static extern bool SetHandleInformation(IntPtr hObject, int dwMask, int dwFlags);
[DllImport(kernel32, CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe static extern bool CreateProcessW(string lpApplicationName, string lpCommandLine, void* lpProcessAttributes, void* lpThreadAttributes, bool bInheritHandles, int dwCreationFlags, void* lpEnvironment, string lpCurrentDirectory, STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
[DllImport(kernel32, SetLastError = true)]
public unsafe static extern bool ReadFile(IntPtr hFile, byte* lpBuffer, int nNumberOfBytesToRead, out int lpNumberOfBytesRead, void* lpOverlapped);
[DllImport(kernel32, SetLastError = true)]
public unsafe static extern bool WriteFile(IntPtr hFile, byte* lpBuffer, int nNumberOfBytesToWrite, int* lpNumberOfBytesWritten, void* lpOverlapped);
[DllImport(kernel32, SetLastError = true)]
public static extern bool SetConsoleCP(uint wCodePageID);
[DllImport(kernel32, SetLastError = true)]
public static extern bool SetConsoleOutputCP(uint wCodePageID);
[DllImport(kernel32, SetLastError = true)]
public static extern int WaitForSingleObject(IntPtr hHandle, int dwMilliseconds);
[DllImport(kernel32, SetLastError = true)]
public static extern bool GetExitCodeProcess(IntPtr hProcess, out int lpExitCode);
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES {
public int nLength;
public IntPtr lpSecurityDescriptor;
public bool bInheritHandle;
}
[StructLayout(LayoutKind.Sequential)]
public struct STARTUPINFO {
public int cb;
public IntPtr lpReserved, lpDesktop, lpTitle;
public int dwX, dwY, dwXSize, dwYSize, dwXCountChars, dwYCountChars, dwFillAttribute, dwFlags;
public short wShowWindow, cbReserved2;
public IntPtr lpReserved2, hStdInput, hStdOutput, hStdError;
}
[StructLayout(LayoutKind.Sequential)]
public struct PROCESS_INFORMATION {
public IntPtr hProcess, hThread;
public int dwProcessId, dwThreadId;
}
}