I am using memcpy()function..

memcpy(&_bpb, bBootSector, 512);

where _bpb is the variable of structure, bBootSector is byte array

the whole progran works fine but at the exit it generates the following error:

"Run-Time Check Failure #2 - Stack around the variable '_bpb' was corrupted."

Can any one please guide me how it can be solved..I am compiling the program in visual studio 2005...

Well that really depends on what type _bpb is.
If it's anything other than say unsigned char _bpb[512] then you're likely doing something wrong.

Post some code, in particular, some declarations of the variables involved.

typedef struct _BIOS_PARAM_BLOCK
{

   BYTE jumpCode[3];
   BYTE oemName[8];
   WORD bytes_Sector;
   BYTE sec_Cluster;
   WORD size_Sector_Reserved;
   ....... other attributes are also present

} BPB;         // This is the structure 

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
// ..... usual default code.....

BYTE bBootSector[512];
      memset(bBootSector, 0, 512);
      DWORD dwBytesRead(0);
      [B]BPB _bpb;[/B]
      HANDLE hUSB = NULL;
      hFloppy = CreateFile(_T("\\\\.\\F:"),  GENERIC_READ, _SHARE_READ, NULL,        
                OPEN_EXISTING, 0, NULL);                 
      if(hUSB != NULL)
      {    
 // Read boot sector
         if (!ReadFile(hUSB, bBootSector, 512, &dwBytesRead, NULL))
         {
            cout<<"Error in reading Usb\n";
         }
         else
         {
            [B]memcpy(&_bpb, bBootSector, 512);     [/B]        
          }
closeHandle(hUSB);
               }
   }

   getch();
   return nRetCode;
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Yeah, did you miss all the "read first" bits which explain code tags?

First thing, add

if ( sizeof(_bpb) != 512 ) {
  cout << "bpb wrong size";
} else {
  // carry on with your code to read and memcpy
}

Notice how this short snippet is formatted!

ya you are right it says that that _bpb has wrong size... Thanks alot My problem is solved..

This question has already been answered. Start a new discussion instead.