Weird ReadProcessMemory problem
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 02 May 2007 00:20:00 -0400
It took some time to track this one down.
Main GUI thread spawns worker thread
Worker thread does a CreateProcess, gets a process handle for the process
Worker thread enters a debug-event loop, does things until process stops
Worker thread does a PostMessage to main GUI thread
Worker thread terminates
Main GUI thread receives notification
Main GUI thread attempts to ReadProcessMemory
ReadProcessMemory fails with "access denied"
Main GUI thread closes process handle
The solution seems to be
Main GUI thread creates event
Main GUI thread spawns worker thread
Worker thread does a CreateProcess
Worker thread enters debug-event loop
Worker thread does PostMessage to main GUI thread
Worker thread waits on event
Worker thread closes event handle
Main GUI thread receives notification
Main GUI thread performs (successfully) ReadProcessMemory
Main GUI thread closes process handle
Main GUI thread does SetEvent to let worker thread finish
Note that this behavior, that ReadProcessMemory will not work if the thread that created
the process terminates (it makes no sense, actually), is undocumented. It may be that it
would work if I had not used WaitForDebugEvent, but if so, this is also undocumented.
(I'm working on a simple performance analyzer. Stay tuned for later publication...)
joe
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Weird ReadProcessMemory problem
- From: Michael K. O'Neill
- Re: Weird ReadProcessMemory problem
- From: Norman Diamond
- Re: Weird ReadProcessMemory problem
- Prev by Date: Re: what's the differents between MFC Wnd && .net winform??
- Next by Date: Re: API TO get User Name
- Previous by thread: Re: API TO get User Name
- Next by thread: Re: Weird ReadProcessMemory problem
- Index(es):
Relevant Pages
|