By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,268 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,268 IT Pros & Developers. It's quick & easy.

does the windows file handle change?

P: n/a
does the windows file handle change?

are file handles unique to the whole operating system or just the current
directoy? if a file is opened then closed then opened again, does the file
handle remain the same?
Nov 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Daniel wrote:
does the windows file handle change?

are file handles unique to the whole operating system or just the
current directoy? if a file is opened then closed then opened again,
does the file handle remain the same?


Do you mean the handle returned from something like the Win32
CreateFile? The handle you are given is essentially an index into a
table of memory addresses. The memory address is pointer to a structure
in the process's memory that the OS uses to access the file. This handle
is only valid in this process for the lifetime of the process (or until
CloseHandle is called).

After you call CloseHandle that handle becomes invalid because the
memory structure it points to will have been released. For this reason
there is no point in passing a file handle to another machine, nor
persisting it in a database or a file. You can pass a handle to another
process, but to do so, you have to call DuplicateHandle, which in effect
creates a memory structure in the other process and copies the data
across.

When a file is created the memory structure referred to by the handle
will be information about the file. If you close the file (CloseHandle)
the memory will be released and the handle will be invalid. If you open
the file again, a new memory structure will be created with essentially
the same data, but it will most likely be in a different memory address
and most likely the index of it in the process's table will be different
and hence the handle returned will most likely be different.

Richard
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.