anshdadhich commited on
Commit
c878efa
·
verified ·
1 Parent(s): 36690d3

CRITICAL FIX: ERROR_HANDLE_EOF = 38 (raw Win32), not 0x80070026 (HRESULT). GetLastWin32Error returns raw codes. Rust windows-rs wraps as HRESULT which confused the original port.

Browse files
FastSeekWpf/NativeInterop/Win32Api.cs CHANGED
@@ -30,18 +30,12 @@ internal static class Win32Api
30
  public const uint OPEN_EXISTING = 3;
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 ──
37
- // CRITICAL: These must match the Windows SDK exactly. Previous versions had
38
- // typos (0x900B03 instead of 0x900B3, 0x900F44 instead of 0x900F4) which
39
- // caused DeviceIoControl to return ERROR_INVALID_FUNCTION.
40
- // Verified against windows-rs crate and Windows SDK winioctl.h.
41
  public const uint FSCTL_ENUM_USN_DATA = 0x000900B3;
42
  public const uint FSCTL_QUERY_USN_JOURNAL = 0x000900F4;
43
  public const uint FSCTL_READ_USN_JOURNAL = 0x000900BB;
44
- public const uint FSCTL_READ_FILE_USN_DATA = 0x000900EB;
45
 
46
  // USN reasons
47
  public const uint USN_REASON_FILE_CREATE = 0x00000100;
@@ -49,9 +43,12 @@ internal static class Win32Api
49
  public const uint USN_REASON_RENAME_OLD_NAME = 0x00001000;
50
  public const uint USN_REASON_RENAME_NEW_NAME = 0x00002000;
51
 
52
- // Error codes
53
- public const uint ERROR_HANDLE_EOF = 0x80070026;
54
- public const uint ERROR_JOURNAL_NOT_ACTIVE = 1179;
 
 
 
55
 
56
  // DWM
57
  public const int DWMWA_WINDOW_CORNER_PREFERENCE = 33;
@@ -77,7 +74,7 @@ internal static class Win32Api
77
  out uint lpNumberOfBytesRead,
78
  IntPtr lpOverlapped);
79
 
80
- // Unsafe overload: read into a byte[] at a given offset via GCHandle
81
  public static unsafe bool ReadFile(
82
  IntPtr hFile,
83
  byte[] lpBuffer,
 
30
  public const uint OPEN_EXISTING = 3;
31
  public const uint FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
32
  public const uint FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;
 
 
33
 
34
  // ── IOCTL codes ──
35
+ // From Windows SDK winioctl.h. Verified against windows-rs crate.
 
 
 
36
  public const uint FSCTL_ENUM_USN_DATA = 0x000900B3;
37
  public const uint FSCTL_QUERY_USN_JOURNAL = 0x000900F4;
38
  public const uint FSCTL_READ_USN_JOURNAL = 0x000900BB;
 
39
 
40
  // USN reasons
41
  public const uint USN_REASON_FILE_CREATE = 0x00000100;
 
43
  public const uint USN_REASON_RENAME_OLD_NAME = 0x00001000;
44
  public const uint USN_REASON_RENAME_NEW_NAME = 0x00002000;
45
 
46
+ // Win32 error codes (raw, NOT HRESULT)
47
+ // Marshal.GetLastWin32Error() returns these raw codes.
48
+ // Rust windows-rs wraps them as HRESULT (0x8007XXXX).
49
+ public const int ERROR_HANDLE_EOF = 38; // Raw: 0x26
50
+ public const int ERROR_INSUFFICIENT_BUFFER = 122; // Raw: 0x7A
51
+ public const int ERROR_JOURNAL_NOT_ACTIVE = 1179; // Raw: 0x49B
52
 
53
  // DWM
54
  public const int DWMWA_WINDOW_CORNER_PREFERENCE = 33;
 
74
  out uint lpNumberOfBytesRead,
75
  IntPtr lpOverlapped);
76
 
77
+ // Unsafe overload: read into a byte[] at a given offset — matches Rust ReadFile into &mut buffer[leftover..]
78
  public static unsafe bool ReadFile(
79
  IntPtr hFile,
80
  byte[] lpBuffer,