114 lines
5.2 KiB
C#
114 lines
5.2 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace DTS.Common.Utilities
|
|
{
|
|
//disables xml comments missing warning - this file is just a wrapper for win32
|
|
//imports, documentation can be found in win32 api or headers.
|
|
#pragma warning disable 1591
|
|
|
|
/// <summary>
|
|
/// win32 I/O declarations
|
|
/// </summary>
|
|
public class FileIOApiDeclarations
|
|
{
|
|
|
|
// API declarations relating to file I/O.
|
|
|
|
// ******************************************************************************
|
|
// API constants
|
|
// ******************************************************************************
|
|
|
|
public const uint GENERIC_READ = 0x80000000;
|
|
public const uint GENERIC_WRITE = 0x40000000;
|
|
public const uint FILE_SHARE_READ = 0x00000001;
|
|
public const uint FILE_SHARE_WRITE = 0x00000002;
|
|
public const uint FILE_FLAG_OVERLAPPED = 0x40000000;
|
|
public const int INVALID_HANDLE_VALUE = -1;
|
|
public const short OPEN_EXISTING = 3;
|
|
public const int WAIT_TIMEOUT = 0x102;
|
|
public const uint WAIT_OBJECT_0 = 0;
|
|
public const uint WAIT_FAILED = 0xFFFFFFFF;
|
|
public const uint WAIT_ABANDONED = 0x00000080;
|
|
public const int FSCTL_SET_COMPRESSION = 0x9C040;
|
|
|
|
// ******************************************************************************
|
|
// Structures and classes for API calls, listed alphabetically
|
|
// ******************************************************************************
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct OVERLAPPED
|
|
{
|
|
public int Internal;
|
|
public int InternalHigh;
|
|
public int Offset;
|
|
public int OffsetHigh;
|
|
public int hEvent;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct SECURITY_ATTRIBUTES
|
|
{
|
|
public int nLength;
|
|
public int lpSecurityDescriptor;
|
|
public int bInheritHandle;
|
|
}
|
|
|
|
// ******************************************************************************
|
|
// API functions, listed alphabetically
|
|
// ******************************************************************************
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern int CancelIo(int hFile);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern int CloseHandle(int hObject);
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
|
public static extern int CreateEvent(ref SECURITY_ATTRIBUTES SecurityAttributes, int bManualReset, int bInitialState, string lpName);
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
|
public static extern int CreateFile(string lpFileName,
|
|
uint dwDesiredAccess,
|
|
uint dwShareMode,
|
|
ref SECURITY_ATTRIBUTES lpSecurityAttributes,
|
|
int dwCreationDisposition,
|
|
uint dwFlagsAndAttributes,
|
|
int hTemplateFile);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern int GetLastError();
|
|
|
|
[DllImport("kernel32.dll")]
|
|
// static public extern int ReadFile(int hFile, ref byte lpBuffer, int nNumberOfBytesToRead, ref int lpNumberOfBytesRead, ref OVERLAPPED lpOverlapped);
|
|
public static extern int ReadFile(int hFile, ref byte lpBuffer, int nNumberOfBytesToRead, ref int lpNumberOfBytesRead, int lpOverlapped);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern uint WaitForSingleObject(int hHandle, int dwMilliseconds);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern int WriteFile(int hFile, ref byte lpBuffer, int nNumberOfBytesToWrite, ref int lpNumberOfBytesWritten, int lpOverlapped);
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
|
|
|
public static extern int DeviceIoControl(IntPtr hDevice,
|
|
int dwIoControlCode,
|
|
ref short lpInBuffer,
|
|
int nInBufferSize,
|
|
IntPtr lpOutBuffer,
|
|
int nOutBufferSize,
|
|
ref int lpBytesReturned,
|
|
IntPtr lpOverlapped);
|
|
|
|
/*public static extern bool DeviceIoControl(int hDevice,
|
|
int dwIoControlCode,
|
|
ref int lpInBuffer,
|
|
uint nInBufferSize,
|
|
ref int lpOutBuffer,
|
|
uint nOutBufferSize,
|
|
out int lpBytesReturned,
|
|
uint lpOverlapped);*/
|
|
}
|
|
#pragma warning restore 1591
|
|
}
|