[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3015
  • Last Modified:

Direct Memory Access in C

Hi all,

Is there a way to directly access memory in Windows with c.  I have tried several attempts but keep getting AV's.  Here's some code to show what I'm doing.

int main(int argc, char* argv[])
{
      
long* p = (long*) 0x00AFAED8; //Want to know the value at this address
long t = 0;

t = *p;
      
      return 0;
}
0
windows_programing
Asked:
windows_programing
3 Solutions
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi windows_programing,

You can do this kind of thing, but you need to keep a couple of things in mind.

1)  The address that you're reading is the memory within your address space, it is NOT the system address.
2)  If you attempt to read an address that's not assigned to your program, it will abort.
3)  You'll probably want to use (unsigned char *) instead of (long*).


But, Good Luck!
Kent
0
 
rajeev_devinCommented:
>> Is there a way to directly access memory in Windows with c.
You can access but not the system address space. You can access the user address space.

A process is divided into two memory address space.
System address space // Kernel-mode program can access this address space.
& User address space // User-mode program can access this address space.

So be careful to avoid program crash.

For more details check this link
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q189327
0
 
grg99Commented:
In Windows it never makes any sense to try to peek at some absolute memory address.   Windows is a 99% all-relocaatable and virtual system.  There are darned few absolute addresses that are of any significance.  And in your typical user program, the adddresses are all relative to the user data segment, not any absolute physical memory address.

SO I guess the better question is:  why do you want to peek at that address?    Maybe we can suggest a better way of doing whatever yuo're trying to do.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
windows_programingAuthor Commented:
I'm trying to write an external debug routine (another software app.) that will give me info. on my software.

I think I've found something of interest from MSDN..
ReadProcessMemory()
0
 
grg99Commented:
ah yes, that's the ticket.  Good luck with your debugger.

0
 
windows_programingAuthor Commented:
Thanks for the help on this one!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now