init
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DTS.Common.USBFramework
|
||||
{
|
||||
public class FileIODeclarations
|
||||
{
|
||||
|
||||
// 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 class FileIO
|
||||
{
|
||||
public const short FILE_ATTRIBUTE_NORMAL = 0X80;
|
||||
public const int FILE_FLAG_OVERLAPPED = 0X40000000;
|
||||
public const short FILE_SHARE_READ = 0X1;
|
||||
public const short FILE_SHARE_WRITE = 0X2;
|
||||
public const uint GENERIC_READ = 0X80000000;
|
||||
public const uint GENERIC_WRITE = 0X40000000;
|
||||
public const int INVALID_HANDLE_VALUE = -1;
|
||||
public const short OPEN_EXISTING = 3;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct SECURITY_ATTRIBUTES
|
||||
{
|
||||
public int nLength;
|
||||
public IntPtr lpSecurityDescriptor;
|
||||
public int bInheritHandle;
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern bool CloseHandle(SafeFileHandle hObject);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, int dwShareMode, ref SECURITY_ATTRIBUTES lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user