views:

189

answers:

1

I have some C# code that is calling CreateFile on a different physical device path each time through a loop(ie \.\PhysicalDrive1, then \.\PhysicalDrive2, ...) via pInvoke and then using the returned handle do some other low level windows stuff. At the end of the loop it calls CloseHandle on the handle.

While debugging I noticed that the int value of the handle was the same each pass through the loop. I can see this being either expected (windows is just reusing the handle) or unexpected (the handle wasn't released last pass).

So I just want to verify whether or not this is expected (or at least not incorrect) behaviour.

+2  A: 

A handle is just an index to some entry into some table in the kernel. If you are opening and closing a handle repeatedly, it is entirely possible for it to get the exact same entry in the table and hence the same index.

Be aware that this is implementation specific and can change with any new release, service pack, or QFE.

Michael
Thanks, that was what my intuition said, but needed the validation.
BioBuckyBall