471,089 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

does the windows file handle change?

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
1 1550
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.

Similar topics

reply views Thread by Wayne Gibson | last post: by
4 posts views Thread by Tamir Khason | last post: by
1 post views Thread by Daniel | last post: by
4 posts views Thread by Jim Michaels | last post: by
14 posts views Thread by Anoop | last post: by
38 posts views Thread by JTL | last post: by
6 posts views Thread by Lord Zoltar | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.