Click to See Complete Forum and Search --> : Getting handle of an already open file.


Quell
February 17th, 2005, 07:44 AM
helo.
here is the situation.
i have a program A that injection a dll into program B. Now the program B has a file open in its memory , i know the file's name and location. I want my dll that was injection by Program A, to get the handle of that file that is already opened from Program B, second time. BAsicly i ned to controlse the file , being able to copy it etc from my dll..how would i get the handle that is already open?
thx

hankdane
February 23rd, 2005, 03:35 PM
Filehandles works at the process-level, so you can reuse the handle in your dll -- with caution; if you change the file pointer that B is relying on, you can crash the program pretty badly, or worse, cause data loss.

Since you know the name and location, you can always try to reopen the file with the CreateFile() function, but this will not work if B has opened the file with exclusive access.