Upload FastSeekWpf/NativeInterop/Win32Api.cs
Browse files
FastSeekWpf/NativeInterop/Win32Api.cs
CHANGED
|
@@ -31,7 +31,6 @@ internal static class Win32Api
|
|
| 31 |
public const uint FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
|
| 32 |
public const uint FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;
|
| 33 |
public const uint FILE_FLAG_NO_BUFFERING = 0x20000000;
|
| 34 |
-
public const uint FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
|
| 35 |
public const uint FILE_ATTRIBUTE_NORMAL = 0x00000080;
|
| 36 |
|
| 37 |
// IOCTL codes
|
|
@@ -74,6 +73,29 @@ internal static class Win32Api
|
|
| 74 |
out uint lpNumberOfBytesRead,
|
| 75 |
IntPtr lpOverlapped);
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
[DllImport("kernel32.dll", SetLastError = true)]
|
| 78 |
public static extern bool SetFilePointerEx(
|
| 79 |
IntPtr hFile,
|
|
|
|
| 31 |
public const uint FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
|
| 32 |
public const uint FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;
|
| 33 |
public const uint FILE_FLAG_NO_BUFFERING = 0x20000000;
|
|
|
|
| 34 |
public const uint FILE_ATTRIBUTE_NORMAL = 0x00000080;
|
| 35 |
|
| 36 |
// IOCTL codes
|
|
|
|
| 73 |
out uint lpNumberOfBytesRead,
|
| 74 |
IntPtr lpOverlapped);
|
| 75 |
|
| 76 |
+
// Unsafe overload: read into a byte[] at a given offset via GCHandle
|
| 77 |
+
public static unsafe bool ReadFile(
|
| 78 |
+
IntPtr hFile,
|
| 79 |
+
byte[] lpBuffer,
|
| 80 |
+
int offset,
|
| 81 |
+
uint nNumberOfBytesToRead,
|
| 82 |
+
out uint lpNumberOfBytesRead,
|
| 83 |
+
IntPtr lpOverlapped)
|
| 84 |
+
{
|
| 85 |
+
fixed (byte* p = &lpBuffer[offset])
|
| 86 |
+
{
|
| 87 |
+
return ReadFilePointer(hFile, p, nNumberOfBytesToRead, out lpNumberOfBytesRead, lpOverlapped);
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
[DllImport("kernel32.dll", SetLastError = true, EntryPoint = "ReadFile")]
|
| 92 |
+
private static extern unsafe bool ReadFilePointer(
|
| 93 |
+
IntPtr hFile,
|
| 94 |
+
byte* lpBuffer,
|
| 95 |
+
uint nNumberOfBytesToRead,
|
| 96 |
+
out uint lpNumberOfBytesRead,
|
| 97 |
+
IntPtr lpOverlapped);
|
| 98 |
+
|
| 99 |
[DllImport("kernel32.dll", SetLastError = true)]
|
| 100 |
public static extern bool SetFilePointerEx(
|
| 101 |
IntPtr hFile,
|