내 프로그램 "Kernel32.dll"기능을 사용하여 WinXP SP3 OS (외장 HDD)의 원시 디스크 섹터에 액세스하고 있습니다.외부 HDD에서 높은 오프셋 (4G 이상)의 원시 섹터 액세스
프로그램이 섹터 번호 8388607에 도달 할 때까지 모든 것이 잘 작동합니다. 즉, SetFilePointer에서 바이트 오프셋이 32 비트 (단위! 그러나 아래 코드는 모든 변수를 "long"으로 사용합니다. 내가 뭘 잘못하고 있니? (버튼 클릭 "덤프"에 대한)
코드 :
int drive = DRV.SelectedIndex; // DRV is the drive combo box
long bps = BytesPerSector(drive), spt = GetTotalSectors(drive);
string dr = DRV.SelectedItem.ToString();
int moveToHigh, read = 0;
uint GENERIC_READ = 0x80000000;
uint OPEN_EXISTING = 3;
SafeFileHandle handleValue = CreateFile(dr, GENERIC_READ, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
if (handleValue.IsInvalid)
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
// idx = Loop starting index
// FS = The starting sector index
// TS = The final sector index
long idx = (FS == -1) ? 0 : FS, tot = (TS == -1) ? spt : TS;
for (; idx < tot; idx++)
{
byte[] b = new byte[bps];
// HERE IS THE ISSUE!!!
SetFilePointer(handleValue, idx*bps), out moveToHigh, EMoveMethod.Current);
if (ReadFile(handleValue, b, bps, out read, IntPtr.Zero) == 0)
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
if (this.IsDisposed == true) { handleValue.Close(); break; }
Application.DoEvents();
}
handleValue.Close();
kernel32.dll에서 외부 함수 :
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern uint SetFilePointer(
[In] SafeFileHandle hFile,
[In] long lDistanceToMove,
[Out] out int lpDistanceToMoveHigh,
[In] EMoveMethod dwMoveMethod);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess,
uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,
uint dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport("kernel32", SetLastError = true)]
internal extern static int ReadFile(SafeFileHandle handle, byte[] bytes,
int numBytesToRead, out int numBytesRead, IntPtr overlapped_MustBeZero);
내가 많은 것을 시도했다, 그러나 아무 생각이 무슨 없으며, 응용 프로그램 그냥 치명적인 예외로 끝날 버그보고를 보내달라고
고마워요
그러면 어떻게됩니까? 오류? 그리고 왜 정수에 double을 사용합니까? 또한 .NET에서 길다는 것은 Win32API에서 길다는 것과 다릅니다. –