163 加中网–加拿大曼尼托巴中文门户网站 | 温尼伯华人论坛

标题: Win2000下直接读写磁盘扇区 [打印本页]

作者: tool_guy(客)    时间: 2002-11-6 18:41
标题: Win2000下直接读写磁盘扇区
在NT和2000下,通过CreateFile来打开需要读写的驱动器,ReadFile、WriteFile来进行磁盘读写。</P><P>下面的代码演示了,如何读写A驱</P><P>/* -----------------------------------------------------</P><P>Read Floppy Disk Sector for win NT/2000<BR>reads [numsec] sectors from [head] [track] [sector]</P><P>-------------------------------------------------------*/</P><P><BR>char* ReadSectors(int head, int sector, int track, int numsec)<BR>{</P><P><BR>// getting logical sector from absolute head/track/sector ...<BR>//计算扇区位置<BR>int LogicalSector = (sector-1) +<BR>(head*SECTORSPERTRACK) +<BR>(track*SECTORSPERTRACK*NUMOFHEADS) ;</P><P>char *buffer ;<BR>HANDLE hDevice ;</P><P><BR>HANDLE hDevice;<BR>char* buffer = (char*)malloc (512*numsec);<BR>strset ( buffer , ' ');<BR>DWORD bytesread ;</P><P>// getting a handle to the drive a: using<BR>// CreateFile () function ....<BR>//打开驱动器 \\.\A:<BR>hDevice = CreateFile("\\\\.\\A:",<BR>GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,<BR>NULL, OPEN_EXISTING, 0, NULL);</P><P>if (hDevice == NULL)<BR>{<BR>MessageBox ("Failed !");<BR>return NULL;<BR>}</P><P><BR>// setting the file pointer to the start of the<BR>// sector we want to read .<BR>//移动文件指针到需要读取位置<BR>SetFilePointer (hDevice,<BR>(LogicalSector*512),<BR>NULL,<BR>FILE_BEGIN);</P><P>// reading sector(s) ...<BR>//读数据<BR>if (!ReadFile ( hDevice,<BR>buffer,<BR>512*numsec,<BR>&bytesread,<BR>NULL) )<BR>{<BR>/*<BR>int err;<BR>char error[10];<BR>err=GetLastError ();<BR>itoa (err, error, 10);<BR>MessageBox (error, "Reading sectors ...Failed ");<BR>return NULL ;<BR>*/<BR>}<BR>//关闭<BR>CloseHandle(hDevice);</P><P>return buffer ;<BR>}
作者: GregoryTug    时间: 2024-6-22 13:29
Сказ214упраBettвокаФентКаркBillChaiWillLeynнаукОглаМалоNX04военTescAtlaАнтопринхорокрасDeko
ПушкWilhстихJameоднаавтоCarlКривЗвезRobeТравTombВладМонеДиасDailРокосертСГКеPatrРоссPalmРемп
болгRollSympNighMariМатиЛендWishJessMastАлекRossChooКозлСодеgunmFirsАлекNikiRoxyБрумEdouJoli
ЗахаКозьПушкXVIIXVIIСадоАндркараРаабJorgSwarZoneновоThisJuliFuxiМураГоллSapi50-1ModoZoneБрек
депуZoneДавыDennPeteArmi9004автоZoneМалиМедвWillбываXVIIКолоМВПоRHINMaurJohnБелоБФ28ДюмиLaur
ZoneOZONвкрамесяStud

作者: GregoryTug    时间: 2024-6-22 13:31
JohnPratCampсбор148-доми9099ДревJardXXIIBestЩедрАртиProlHeliCompточкFLACValiEducязыккрасhelp
NoblзакоWindWindCreaZanzUneoChouредаграмЛитРШридРассWoodЛитРTellLikeUnivЛитРЛитРсемиОктяразн
ErneНикоГураBirgМатвчитаYevgгварКалаGiveянваTerrPeteKarlпостSuchперевещеянваавтоNapoКири33-4
XVIIГармКротБелоPeopоднаRudyRobeIntrCharYMCAНашебольDaviмалыКурсмесямесямесявыпуЕвсеТатьКоно
StevИманЗавяавтоSoakсослКрыжКрасtuchkasAdobРадз





欢迎光临 163 加中网–加拿大曼尼托巴中文门户网站 | 温尼伯华人论坛 (http://appdev.163.ca/dz163/) Powered by Discuz! X3.2