using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Apewer.Internals.Interop
{
[System.Security.SecuritySafeCritical]
class Kernel32
{
///
///
///
[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
public static extern int CloseHandle(int hObject);
/// 关闭内核对象句柄。
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseHandle(IntPtr handle);
/// 打开要映射的文件。
///
///
///
///
///
///
///
///
[DllImport("kernel32.dll")]
public static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, FileShare dwShareMode, IntPtr securityAttrs, FileMode dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
/// 内存映射文件句柄。
///
///
///
///
///
///
///
[DllImport("kernel32.dll")]
public static extern IntPtr CreateFileMapping(IntPtr hFile, IntPtr lpFileMappingAttributes, uint flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
///
///
///
///
///
[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr CreateMutex(IntPtr lpMutexAttributes, int bInitialOwner, string lpName);
///
///
///
///
///
///
///
///
///
///
///
///
[DllImport("kernel32.dll")]
public static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref StartupInfo lpStartupInfo, ref ProcessInformation lpProcessInformation);
///
///
///
///
[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetExitCodeProcess(int hProcess, out int lpExitCode);
/// 得到文件大小。
///
///
///
[DllImport("kernel32.dll", SetLastError = true)]
public static extern uint GetFileSize(IntPtr hFile, out uint highSize);
///
///
///
[DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("kernel32.dll", ExactSpelling = true)]
public static extern IntPtr GetCurrentProcess();
///
///
///
///
///
[DllImport("kernel32")]
public static extern int GetShortPathName(string lpszLongPath, string lpszShortPath, int cchBuffer);
/// 得到系统信息。
///
[DllImport("kernel32.dll", SetLastError = true)]
public static extern void GetSystemInfo(ref SystemInfo lpSystemInfo);
/// 内存映射文件。
///
///
///
///
///
///
[DllImport("kernel32.dll")]
public static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, uint dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, uint dwNumberOfBytesToMap);
///
///
///
///
[DllImport("kernel32", BestFitMapping = false, CharSet = CharSet.Auto, SetLastError = true, ThrowOnUnmappableChar = true)]
public static extern int MoveFile([MarshalAs(UnmanagedType.LPTStr)] [In] string lpExistingFileName, [MarshalAs(UnmanagedType.LPTStr)] [In] string lpNewFileName);
///
///
///
///
///
[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr OpenMutex(uint dwDesiredAccess, int bInheritHandle, string lpName);
///
///
///
///
///
[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
public static extern int OpenProcess(int dwDesiredAccess, int bInheritHandle, int dwProcessId);
/// Copies the contents of a source memory block to a destination memory block, and supports overlapping source and destination memory blocks.
/// A pointer to the destination memory block to copy the bytes to.
/// A pointer to the source memory block to copy the bytes from.
/// The number of bytes to copy from the source to the destination.
[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
public static extern void RtlMoveMemory(ref double Destination, int Source, int Length);
///
///
///
[DllImport("kernel32")]
public static extern int Sleep(int millisecond);
/// 撤消文件映像。
///
///
[DllImport("kernel32.dll")]
public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
}
}