关于setfilepointer函数和readfile函数的问题
大家好:我想要读取本地磁盘扇区,现在已经获得句柄之后用如下函数进行读取工作
private static extern bool ReadFile(
IntPtr hFile,
byte[] lpBuffer
int nNumberOfBytesToRead,
int lpNumberOfBytesRead,
ref OVERLAPPED flag//OVERLAPPED lpOverlapped overlapped buffer
);
其中OVERLAPPED 定义如下
private struct OVERLAPPED
{
public int Internal;
public int InternalHigh;
public int Offset;
public int OffsetHigh;
public int hEvent;
}
setfilepointer函数定义如下
private static extern int SetFilePointer ( int hFile, int lDistanceToMove, int lpDistanceToMoveHigh, int dwMoveMethod);
调用的如下
long w=SetFilePointer(int.Parse(aw.ToString()),512,0,0);
ReadFile(aw,aaaa,512,a3,0);
aw为createfile函数返回的句柄
aaaa为读取出的内容所存的数组
现在的情况是,指针移动不了,也就是不管怎么改变setfilepointer函数的参数,readfile函数读取出的都是从头开始的512个字节的数据,哪位大牛帮着看看,问题出在哪,谢谢 --------------------编程问答-------------------- up --------------------编程问答-------------------- 解决了么 ?
我也遇到同样问题 --------------------编程问答-------------------- 楼主设置了StructLayout特性没有?
--------------------编程问答-------------------- 楼主啊能不能将你的代码帖上来看看啊?我遇到了同样的问题困扰我好几天了啊 --------------------编程问答-------------------- long w=SetFilePointer(int.Parse(aw.ToString()),512,0,0);
[StructLayout(LayoutKind.Sequential)]
private struct OVERLAPPED
{
public int Internal;
public int InternalHigh;
public int Offset;
public int OffsetHigh;
public int hEvent;
}
最后一个参数不应该是0吧,0代表FILE_BEGIN,表示从文件的开头开始;
Value Meaning
FILE_BEGIN 0
The starting point is zero or the beginning of the file.
FILE_CURRENT 1
The starting point is the current value of the file pointer.
FILE_END 2
The starting point is the current end-of-file position.
from MSDN
补充:.NET技术 , C#