Accessing a process memory from a thread
-
Saturday, September 22, 2012 10:53 AM
I access another program's memory from my main window code, that looks like this:
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); if (Process32First(snapshot, &entry) == TRUE) { while (Process32Next(snapshot, &entry) == TRUE) { if (stricmp(entry.szExeFile, processname) == 0) { HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); ...and it works fine but when I move it into a function that is called as a thread using CreateThread() - the code stops working.
Do I need to somehow modify the code so it could work from a thread?
Thanks!
- Edited by alikim Saturday, September 22, 2012 10:54 AM
All Replies
-
Saturday, September 22, 2012 2:25 PM
At which point of shown fragment does it stop working? Maybe you lose the first process returned by Process32First.
-
Saturday, September 22, 2012 4:14 PMWhat you mean by not working. You can debug code and check that at which point it is stopped working. If you give more information we can help you better..
Thanks, Renjith V R
-
Saturday, September 22, 2012 4:48 PM
The problem has been solved, thanks- Marked As Answer by alikim Saturday, September 22, 2012 4:48 PM
-
Saturday, September 22, 2012 5:18 PMCould you please share what was the issue. if so it will be helping others who faces same issue.
Thanks, Renjith V R
-
Monday, September 24, 2012 1:53 AMModerator
Hello alikim,
Thanks for your participation in this forum. And it is glad to see your problem resolved. But it would be better if you share your solution with us. That will help others encounter same issue.
Regards,
Damon Zheng [MSFT]
MSDN Community Support | Feedback to us

