DumpSector始终返回第一个磁盘扇区

时间:2018-09-30 10:04:58

标签: c#

我从here获得了代码
问题是,无论我发送函数的扇区号是什么,它总是转储第一个扇区

user始终返回第一个磁盘扇区

DumpSector(string drive, double sector, int bytesPerSector)

抱歉,我的代码太多。

drive = "\\.\PHYSICALDRIVE1"  
sector = from 0 to totalSectors
bytesPerSector = 512

1 个答案:

答案 0 :(得分:1)

如@HansPassant所说

“ SetFilePointer()声明是完全错误的。原始代码中有错误,但代码段中的情况更糟,看起来它是随机被黑客入侵,直到它停止生成MDA警告为止。在寻求帮助时,请务必提及此类问题。赞成SetFilePointerEx。“

我更改了

 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.ThisCall)]
    static extern uint SetFilePointer(
        [In] SafeFileHandle hFile,
        [In] long lDistanceToMove,
        [Out] out int lpDistanceToMoveHigh,
        [In] EMoveMethod dwMoveMethod);

对此

[DllImport("kernel32.dll")]
        public static extern bool SetFilePointerEx(
            SafeFileHandle hFile, 
            long liDistanceToMove,
            out long lpNewFilePointer, 
            uint dwMoveMethod);

并且我重构了代码中的用法。

相关问题