我要登陆┊我要注册┊设为首页┊收藏本站┊软件下载┊在线助手┊风尚社区 function fontZoom(size) { document.getElementById('fontzoom').style.fontSize=size+'px' } 当前位置:首页 → 列表 → VC++/MFC → 平台/系统 → [文件操作]
百特门软件下载
百特门网址
风尚开发QQ群:529604
风尚开发QQ群:519356
源码下载
Win2000下直接读写磁盘扇区
作者:不详 今年浏览:37 本月浏览:5 今日浏览:2 总浏览:37 日期:2004-09-13
发表人: 风尚开发网:http://www.vwind.com 文章类型: 转载 来源:[大/中/小] 打印
http://www.vwind.com/dev/show.php?id=112&dirid=11&page=
在NT和2000下,通过CreateFile来打开需要读写的驱动器,ReadFile、WriteFile来进行磁盘读写。
下面的代码演示了,如何读写A驱
/* -----------------------------------------------------
Read Floppy Disk Sector for win NT/2000
reads [numsec] sectors from [head] [track] [sector]
-------------------------------------------------------*/
char* ReadSectors(int head, int sector, int track, int numsec)
{
// getting logical sector from absolute head/track/sector ...
//计算扇区位置
int LogicalSector = (sector-1) +
(head*SECTORSPERTRACK) +
(track*SECTORSPERTRACK*NUMOFHEADS) ;
char *buffer ;
HANDLE hDevice ;
HANDLE hDevice;
char* buffer = (char*)malloc (512*numsec);
strset ( buffer , ' ');
DWORD bytesread ;
// getting a handle to the drive a: using
// CreateFile () function ....
//打开驱动器 \\.\A:
hDevice = CreateFile("\\\\.\\A:",
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == NULL)
{
MessageBox ("Failed ");
return NULL;
}
// setting the file pointer to the start of the
// sector we want to read .
//移动文件指针到需要读取位置
SetFilePointer (hDevice,
(LogicalSector*512),
NULL,
FILE_BEGIN);
// reading sector(s) ...
//读数据
if ( ReadFile ( hDevice,
buffer,
512*numsec,
&bytesread,
NULL) )
{
/*
int err;
char error[10];
err=GetLastError ();
itoa (err, error, 10);
MessageBox (error, "Reading sectors ...Failed ");
return NULL ;
*/
}
//关闭
CloseHandle(hDevice);
return buffer ;
}
本文地址:http://com.8s8s.com/it/it25639.htm