正在写一个硬盘修复的工具,开发环境vc6.0,操作系统是winXP,实验的硬盘250GB(四个分区),开发过程中遇到如下问题:
需要利用SetFilePointer对各分区的引导扇区进行定位后再做备份,但SetFilePointer的最大寻址只能到4G(64位),实验硬盘上除了第一分区,其他分区的引导扇区地址都远远的超过了4G,因此自己想当然的将SetFilePointer放到了一个循环中想以此突破4G的界限,结果并不成功,可以读出数据,但数据并非是引导扇区的数据(已经和WinHex读到的数据对比过),现在请问将SetFilePointer嵌套到一个循环中这样的方法有什么不妥?除了内存映射外是否还有其他办法可以用以定位超过4G的地址?
以下是代码: HANDLE HardDriver=CreateFile(_T( "\\\\.\\PHYSICALDRIVE0 "),   GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
BYTE buffer[512];//用以接收引导扇区数据的缓冲区,一个扇区大小
DWORD ReadSize=0;
int Sec2Address=39070143;//这是第二个分区的引导扇区所在的扇区地址,实际地址应该是39070143*512B for(int count=0;count<Sec2Address;count++)//每次循环将文件指针移动一个扇区,循环39070143次后定位到引导扇区
{
::SetFilePointer(HardDriver,512,NULL,FILE_CURRENT);
}
ReadFile(HardDriver,buffer,512*512,&ReadSize,NULL);
恭请各位帮帮小弟!!

解决方案 »

  1.   

    4G(64位),64位不是4G,32位才是,64位是T级别了吧
      

  2.   

    To work with 64-bit file pointers, you can declare a LONG, treat it as the upper half of the 64-bit file pointer, and pass its address in lpDistanceToMoveHigh. This means that you have to treat two different variables as a logical unit, which can cause an error. It is best to use the LARGE_INTEGER structure to create a 64-bit value and pass the two 32-bit values by using the appropriate elements of the union.Also, it is best to use a function to hide the interface to SetFilePointer. The following code example shows you that scenario.
    [C++]__int64 myFileSeek (HANDLE hf, __int64 distance, DWORD MoveMethod)
    {
       LARGE_INTEGER li;   li.QuadPart = distance;   li.LowPart = SetFilePointer (hf, 
                                    li.LowPart, 
                                    &li.HighPart, 
                                    MoveMethod);   if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() 
           != NO_ERROR)
       {
          li.QuadPart = -1;
       }   return li.QuadPart;
    }from msdn
      

  3.   

    NTFS硬盘才能存储超过4G大的文件吧
      

  4.   


    //-----------------------------------------------------------------------------------
    //功能:移动文件指针到指定的位置
    //参数:handle 打开文件的句柄
    // distance 移动的位移
    // MoveMethod 移动的起始位置
    //---------------------------------------------------------------------------------
    LONGLONG MyFileSeek(HANDLE handle, LONGLONG llDistance, DWORD dwMoveMethod)
    {
    LARGE_INTEGER li; li.QuadPart = llDistance;
    li.LowPart = SetFilePointer(handle, li.LowPart, &li.HighPart, dwMoveMethod); if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
    {
    li.QuadPart = -1;
    } return li.QuadPart;
    }
      

  5.   

    认真看看SetFilePointer的第三个参数
    或者用SetFilePointerEx
      

  6.   

    DWORD WINAPI SetFilePointer(
      __in         HANDLE hFile,
      __in         LONG lDistanceToMove,
      __inout_opt  PLONG lpDistanceToMoveHigh,
      __in         DWORD dwMoveMethod
    );lpDistanceToMoveHigh 
    A pointer to the high order 32-bits of the signed 64-bit distance to move. If you do not need the high order 32-bits, this pointer must be set to NULL.When not NULL, this parameter also receives the high order DWORD of the new value of the file pointer. For more information, see the Res section in this topic.
      

  7.   

    SetFilePointerEx   0xFFFFFFFFFFFFFFFF
      

  8.   

    Thx everyone!! this is a stupid problem, I made the most basic fault.
    Thanks a lot,thanks!!!
    .
      

  9.   

    Poor English,i can't understand  what you said.