Jim Lanflte
Jim Lanflte

Reputation: 43

Calling GetHandleInformation before any call to CloseHandle

Fact 1: Due to some client-constraints we are unable to use Exception mechanism.

Fact 2: Closing a handle which was already closed raises an Exception.

Without going through the reasons for the mention facts, will calling GetHandleInformation() to detect whether or not the handle is still valid, and only if it is calling CloseHandle() would be a good way of avoiding such an exception?

Upvotes: 0

Views: 468

Answers (1)

Paul
Paul

Reputation: 6851

You must not access a closed handle in any way, as it may refer to a different handle due to handle recycling.

handle recycling means that any invalid handle can suddenly become valid again (but refer to an unrelated object).

Raymond Chen - The Old New Thing.

Upvotes: 6

Related Questions