想在windows下,也就是保护模式下读取MBR。不知道windows提供了相应的库函数没有?
转
------------
#include
#include
const UINT uSectorSize = 512 ;
const UINT uBegSector = 0 ;
const UINT uSectorNum = 1 ;
const UINT uReadSize = uSectorSize * uSectorNum ;
BYTE bBuffer[uReadSize] = {0} ;
const char pDiskPath[] = "\\\\.\\PHYSICALDRIVE0" ;
void ShowByteInform ( PBYTE pBuf, UINT uSize )
{
for ( UINT i = 1 ; i <= uSize; i++ )
{
printf ( " %02X", pBuf[i-1] ) ;
if ( i % 16 == 0 )
printf ( "\n" ) ;
else if ( i % 8 == 0 )
printf ( " " ) ;
}
}
int main()
{
HANDLE hDisk ;
__try {
hDisk = CreateFile ( pDiskPath, GENERIC_READ, \
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ) ;
if ( hDisk == INVALID_HANDLE_VALUE )
{
MessageBox ( 0, "磁盘打开错误!", 0, 0 ) ;
return 0;
}
SetFilePointer ( hDisk, uBegSector * uSectorSize, 0, FILE_BEGIN ) ;
DWORD dwReadByte ;
ReadFile ( hDisk, (LPVOID)bBuffer, uReadSize, &dwReadByte, NULL ) ;
if ( dwReadByte == 0 )
{
MessageBox ( 0, "磁盘读取错误!", 0, 0 ) ;
return 0;
}
ShowByteInform ( bBuffer, uReadSize ) ;
}
__finally {
CloseHandle ( hDisk ) ;
}
return 0;
}
在98里面行不通,要另想办法,不过也没谁用98了!