Memory Error!! Pls help

Posted on 2004-10-01
Last Modified: 2012-05-05
I have written a code like this in visaul c++ using a win32 API function in a WIN2000 Proffessional.

#include <windows.h>
#include <winbase.h>
void main()
     CopyMemory((LPVOID)0xffffffff,(void *)0x0000ffff,1);

i am getting an error The instruction at "0x00408410" referenced
memory at "0x0000ffff". The memory could not be "read".

I am gettinng the same error when i try to access a memory address of any hex value.
Wot could be the problem?

Thanks in advance!!,
Question by:Abin Thomas
  • 2

Expert Comment

ID: 12201170
you are accessing memory not in user block for that program, you can't just copy memory from somewhere in RAM, it needs to be memory you have allocated in the program you are writing or a much more complex system of IPC communication.

Author Comment

by:Abin Thomas
ID: 12235485
dear demingj1,
  i m  plannming to develop a memory tester program,
  which can read and write to a given memory location.
  so could u help me out in giving ideas or urls?  

Accepted Solution

demingj1 earned 50 total points
ID: 12238453
This seems a pretty good resource for general information regarding memory and memory management across various platforms and languages.  However, most of the information seems pretty general.

I think what you need to do however is run your app in as simple an envronment as possible.  By this I mean run it in DOS or a barebones *nix build.  OS's are a buffer between user programs and memory.  Although it is possible in C++ to map to specific addresses I believe those addresses are in terms of virtual memory and have no bearing on where the data actually lies in RAM.  

When you run your user program you recieve an allocated amount of memory for reading, writing and storing your programs instruction set.  It varies depending on the size and nature of your app, but it is all managed by the OS.  If you try to write (or read) from another programs memory space the OS catches that request, denies it, and terminates your program since it cannot continue after not being able to retrieve the data it needs to continue it's execution.  When you boot a DOS (or Windows 98 Boot Disk) for example, the autoexec.bat file begins calling all programs to set up your environment.  Some of these programs are UMB and/or XMS Memory management and other Memory Management apps, these apps perform the same function by ensuring that the OS's (DOS in this case) memory is protected and not overwritten otherwise even the standard commands like "dir" and "edit" could not guarentee thier integrity since part of their instruction set could be overwritten.

Perhaps I am rambling in error, perhaps what you meant by a memory tester program is a program to test what exact memory space is available test if you can write to certain addresses while inside the Windows OS.  In this case I still don't know how to get through the virtual memory layer, it is embedded pretty deeply into the OS, perhaps somewhere you can find an API or existing native class to access memory directly which also tells Windows Virtual Memory Management to reserve that block of RAM for your code and not write there.  If you found this software you would want to make calls to read/write to a certain block and intercept windows error flags which would be triggering the exception/failure/crash of your program and interpret those error flags appropriately (i.e. your call to CopyMemory((LPVOID)0xffffffff,(void *)0x0000ffff,1); above throws a flag "memory cannot be read") you need to intercept that flag/error before it gets to the OS and the OS terminates your program, if you can intercept the flag you can handle it appropriately inside your program and your program can continue execution.

Hope this helps a bit.


Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question