Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在C++;_C++_Winapi - Fatal编程技术网

C++ 如何在C++;

C++ 如何在C++;,c++,winapi,C++,Winapi,我在读取FAT表时出现运行时错误,错误显示: 变量已损坏 这是我的密码 void Drive::readFatTable() { int c = 0; DWORD nOBTR = 0; HANDLE usb = NULL; usb = CreateFile("\\\\.\\A:",GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,NULL); BYTE buff[513]; memset(buff,0,5

我在读取FAT表时出现运行时错误,错误显示:

变量已损坏

这是我的密码

void Drive::readFatTable()
{
    int c = 0;
    DWORD nOBTR = 0;
    HANDLE usb = NULL;
    usb = CreateFile("\\\\.\\A:",GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,NULL);
    BYTE buff[513];
    memset(buff,0,512);
    if(usb==INVALID_HANDLE_VALUE)
    {
        std::cout<<"ERROR in reading : "<<GetLastError()<<std::endl;
        return;
    }
    UINT32 fat_start = 0;//seek to table
    calc(fat_start);
    seek_to_sect(usb,fat_start,_bpb.BPB_BytsPerSec);
    LPVOID ptr = &fat_table;
    UINT32 ent = 0;
    while(c < _bpb.BPB_FATSz32)
    {
        c++;
        if(!ReadFile(usb,buff,sizeof(BPB),&nOBTR,0))
        {
            std::cout<<"ERROR in reading fat: "<<GetLastError()<<std::endl;
            return;
        }
        BYTE* ptr = buff;
        for (int i=0;i<16;i++)
        {
            memcpy(&ent,ptr,32);
            fat_table.push_back(ent);
            ptr+=32;
        }
    }
    CloseHandle(usb);
    std::cout<<GetLastError()<<std::endl;
    //delete(&fat_start);
}
void Drive::readFatTable()
{
int c=0;
DWORD nOBTR=0;
句柄usb=NULL;
usb=CreateFile(“\\.\\A:”,通用读取,文件共享读取,0,打开现有,0,空);
字节buff[513];
memset(buff,0512);
如果(usb==无效的\u句柄\u值)
{

std::cout您正在将32字节的数据复制到一个4字节的变量中:

UINT32 ent = 0;
memcpy(&ent,ptr,32);

可能不是问题,但是为什么不初始化buff的最后一个元素呢?FAT是否可能异步更改,从而引起注意并被解释为损坏?