Hi...can any1 help me in this code?? i am trying to read the content present at address 0x2c of memory of floppy...but i am having problem in this...please tell me how can i do this???

#include "stdafx.h"
#include "fat_32.h"
#include <conio.h>
#include <memory.h>
#include <string.h>

#ifdef _DEBUG
#define new DEBUG_NEW

// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
   int nRetCode = 0;
   // initialize MFC and print an error on failure
   if (!AfxWinInit(::GetModuleHandle(NULL), NULL,
       ::GetCommandLine(), 0))
      // TODO: change error code to suit your needs
      cerr << _T("Fatal Error: MFC initialization failed") << endl;
      nRetCode = 1;
      // TODO: code your application's behavior here.

	  HANDLE hFloppy = ::CreateFile(_T("\\\\.\\A:"),
                  // Open the A: drive for PHYSICAL ACCESS
                  GENERIC_READ | GENERIC_WRITE,      // Want R/W Access

      if(hFloppy != NULL)
			WORD *temp=new WORD();
			WORD *p;
			p = reinterpret_cast< WORD* > (0x2C);     
			memcpy( temp, p, 2);
            cout<<"contents at 2C are "<<*temp;


         // Close the handle

   return nRetCode;

it gives the following error..

Unhandled exception at 0x10232058 (msvcr80d.dll) in fat_32.exe: 0xC0000005: Access violation reading location 0x0000002c.

Why do you have all that MFC stuff in a console program?

line 54 is illegal. You can't do that -- its not accessing the memory location on a floppy but a memory location somewhere on your computer's RAM.

How to do what you want: I don't know.

I don't know (have no needs) how to access floppies on physical level, but:

1. Use [code] ... [/code] tags to present your snippets.

2. Use

/* not if (hFloppy != NULL) - HANDLE is not a pointer!

3. A very strange, absolutely sensless code:

WORD *temp=new WORD();
WORD *p;
p = reinterpret_cast< WORD* > (0x2C); 
memcpy( temp, p, 2);
cout<<"contents at 2C are "<<*temp;

- Create a pointer to WORD then dynamically allocate WORD and set the pointer to this word.
- Initialize pointer p by 0x2C value with brutal force method (why?!)
- Try to copy two bytes from the address contained in p pointer. Are you sure that it points to the address 0x2C in your process address space (but not on the floppy, of course).
Now p has unsenseless value, and you want to assign it to temp too...

That's enough. You may get access violation in memcpy call or in the next statement. But all these tricks do not bear a relation to that floppy contents...

It's interesting: what for you opened that file?..

If you are interested in what's on the floppy at certain location, you might use ReadFile().

actually i want to know how to read the contents of a particular address in floppy....not the whole sector....so can u tell me please whether ReadFile() can do this..????

The minimum amount you can read/write to a floppy is one sector.

If you want a single byte, then read the sector which contains it, then offset from the start of the memory block.