I have an application that uses readprocessmemory to get information from another application. I think my application causes this other application to crash. Does anyone have any input on this? Why does it cause a crash and how can I change my application?? I cannot modify the other app

thanks

this is in .net 3.5

Recommended Answers

All 7 Replies

We'll need more information than this... generally ReadProcessMemory should not crash the target application of course, so it seems you're doing something 'wrong'... without knowing what exactly you're doing we're in the dark here ;).

Try to down-size the code as much as possible while still crashing the target (e.g. just OpenProcess and ReadProcessMemory): Does it still crash? Does it crash after commenting the ReadProcessMemory call?
Then I think you can make a more informative post.

The thing is where I'm currently reading from it doesn't always crash. Ie it works fine for a few days at a time then all hell breaks loose. I run about 15 instances of this and they all crash at the same time. Basically my program reads the memory of a game server to ensure it's online, and if it's not it will reboot it. There are some memory regions I read that cause it to crash instantly so I'm guessing it's readprocessmem doing it.

Note it's the other application that crashes, not mine. So is readprocessmem like not thread safe? And how can i make it safe?

Why do you need to read the game server's memory to check if it is online?
Take a look at HLSW for example(or any gameserver-listing tool) it basically queries the server on it's game port to see if it responds correctly... you could do the same and restart the gameserver if it is not responding.

Or you can simply check if the process is still running (though in that case you don't really know if the server is connectable... e.g. it could be running without a map loaded).

I've had a look at the function doc @ http://msdn.microsoft.com/en-us/library/ms680553(VS.85).aspx

You seem pretty certain that the issue is in your ReadProcessMemoryFunction().

Can you tell if it has returned a zero value (signalling a fail) when the target server crashes?

What is the last value you read from the specific memory adress when the target server fails?

**Do you get any specific error messages on the server that can indicate what has gone wrong?

Well the problem isn't in my program. My guess is it's an issue with my program reading while that program writes (causing that program to crash). But I'm not sure how to handle cross progam thread safety.

Why are you so fixed on ReadProcessMemory? What's wrong with my suggestion in your case?

I use to do it your way, at this point I'm just curious why readprocessmemory causes errors. I added some time between launch and the initial read which helped. So obviously there's mutability issues which begs the question how do you handle interprocess mutability with readprocessmemory

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.