Sylloge
A C# helper library
code/WinAPI/Kernel32.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Linq;
00004 using System.Text;
00005 using System.Runtime.InteropServices;
00006 using Microsoft.Win32.SafeHandles;
00007 
00008 namespace Sylloge
00009 {
00010     public static partial class WinAPI
00011     {
00012         public static class Kernel32
00013         {
00014             #region Kernel32
00015 
00016             [DllImport("Kernel32.dll", SetLastError = true)]
00017             public static extern IntPtr GetModuleHandle(IntPtr lpModuleName);
00018 
00019             [DllImport("kernel32.dll", SetLastError = true)]
00020             public static extern int CreateNamedPipe(
00021                 String pipeName,
00022                 uint dwOpenMode,
00023                 uint dwPipeMode,
00024                 uint nMAxInstances,
00025                 uint nOutBufferSize,
00026                 uint nInBufferSize,
00027                 uint nDefaultTimeOut,
00028                 IntPtr lpSecurityAttributes);
00029 
00030             [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
00031             public static extern SafeFileHandle CreateFile(string FileName,
00032                                                                 uint DesiredAccess,
00033                                                                 uint ShareMode,
00034                                                                 IntPtr SecurityAttributes,
00035                                                                 uint CreationDisposition,
00036                                                                 uint FlagsAndAttributes,
00037                                                                 IntPtr hTemplateFile);
00038 
00039             [DllImport("kernel32.dll", SetLastError = true)]
00040             public static extern bool CloseHandle(SafeFileHandle hHandle);
00041 
00042             [DllImport("kernel32.dll", SetLastError = true)]
00043             public static extern bool DeviceIoControl(SafeFileHandle hDevice,
00044                                                     uint dwIoControlCode,
00045                                                     IntPtr lpInBuffer,
00046                                                     uint nInBufferSize,
00047                                                     out DiskGeometry OutBuffer,
00048                                                     uint nOutBufferSize,
00049                                                     ref uint lpBytesReturned,
00050                                                     IntPtr lpOverlapped);
00051 
00052             [DllImport("kernel32.dll", SetLastError = true)]
00053             public static extern bool DeviceIoControl(SafeFileHandle hDevice,
00054                                                     uint dwIoControlCode,
00055                                                     bool lpInBuffer, // Prevent media removal
00056                                                     uint nInBufferSize,
00057                                                     IntPtr OutBuffer,
00058                                                     uint nOutBufferSize,
00059                                                     ref uint lpBytesReturned,
00060                                                     IntPtr lpOverlapped);
00061 
00062             [DllImport("kernel32.dll", SetLastError = true)]
00063             public static extern bool DeviceIoControl(SafeFileHandle hDevice,
00064                                                     uint dwIoControlCode,
00065                                                     IntPtr lpInBuffer,
00066                                                     uint nInBufferSize,
00067                                                     IntPtr OutBuffer,
00068                                                     uint nOutBufferSize,
00069                                                     ref uint lpBytesReturned,
00070                                                     IntPtr lpOverlapped);
00071 
00072             [DllImport("kernel32.dll")]
00073             public static extern bool FlushFileBuffers(SafeFileHandle hFile);
00074 
00075             [DllImport("kernel32.dll", SetLastError = true)]
00076             public static extern uint GetDriveType(string lpRootPathName);
00077 
00078             [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
00079             [return: MarshalAs(UnmanagedType.Bool)]
00080             public static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
00081                                                 out ulong lpFreeBytesAvailable,
00082                                                 out ulong lpTotalNumberOfBytes,
00083                                                 out ulong lpTotalNumberOfFreeBytes);
00084 
00085             [DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
00086             public extern static bool GetVolumeInformation(string RootPathName,
00087                                                     StringBuilder VolumeNameBuffer,
00088                                                     int VolumeNameSize,
00089                                                     out uint VolumeSerialNumber,
00090                                                     out uint MaximumComponentLength,
00091                                                     out uint FileSystemFlags,
00092                                                     StringBuilder FileSystemNameBuffer,
00093                                                     int nFileSystemNameSize);
00094 
00095 
00096             [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
00097             public static extern bool GetDiskFreeSpace(string lpRootPathName,
00098                                                         out long lpSectorsPerCluster,
00099                                                         out long lpBytePerSector,
00100                                                         out long lpNumberOfFreeClusters,
00101                                                         out long lpTotalNumberOfClusters);
00102 
00103             [DllImport("kernel32.dll")]
00104             public static extern uint QueryDosDevice(string lpDeviceName, ref StringBuilder lpTargetPath, int ucchMax);
00105 
00106             [DllImport("kernel32.dll", SetLastError = true)]
00107             public static extern bool ReadFile(SafeFileHandle hFile,
00108                                             [Out] byte[] lpBuffer,
00109                                             uint nNumberOfBytesToRead,
00110                                             out uint lpNumberOfBytesRead,
00111                                             IntPtr lpOverlapped);
00112 
00113             [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
00114             public static extern uint SetFilePointerEx(SafeFileHandle hFile,
00115                                                         long liDistanceToMove,
00116                                                         out long lpNewFilePointer,
00117                                                         uint dwMoveMethod);
00118 
00119 
00120 
00121             [DllImport("kernel32.dll", SetLastError = true)]
00122             public static extern uint SetFilePointer([In] SafeFileHandle hFile,
00123                                                     [In] long lDistanceToMove,
00124                                                     int lpDistanceToMoveHigh,
00125                                                     [In] int dwMoveMethod);
00126 
00127 
00128             [DllImport("kernel32.dll", SetLastError = true)]
00129             public static extern bool WriteFile(SafeFileHandle hFile,
00130                                                 byte[] lpBuffer,
00131                                                 uint nNumberOfBytesToWrite,
00132                                                 out uint lpNumberOfBytesWritten,
00133                                                 IntPtr lpOverlapped);
00134 
00135             #endregion
00136         }
00137     }
00138 }
 All Classes Namespaces Files Functions Variables Enumerations Properties Events