CAUSE
Windows NT RegOpenKeyEx always returns a unique handle. Windows 95
RegOpenKeyEx returns the same handle each time the same key is opened.
Windows 95 keeps a reference count, incrementing it each time the key
is opened with RegOpenKeyEx and decrementing it each time the key is
closed with RegCloseKey. The key remains open as long as the reference
count is greater than zero.
Consider the following code:
RegOpenKeyEx(OldKey, NULL, 0, MAXIMUM_ALLOWED, &NewKey)
RegCloseKey(NewKey)
RegQueryValue(NewKey,...)
RegCloseKey(NewKey)
This code is incorrect, but it works under Windows 95 because OldKey and
NewKey refer to the same key. However, the code fails under Windows NT,
because NewKey is not valid after it is closed.
In a related issue, RegOpenKey with a NULL subkey string on Windows NT
will return the same handle that was passed in. Under Windows 95, the
reference count is incremented.
RegOpenKey(OldKey, NULL, 0, MAXIMUM_ALLOWED, &NewKey)
RegCloseKey(OldKey)
RegQueryValue(NewKey,...)
RegCloseKey(NewKey)
This code works under Windows 95 because NewKey is still valid after
closing OldKey, but the code fails under Windows NT. Code that is correct
for Windows NT (don't close the handle until both OldKey and NewKey are no
longer needed) leaks registry handles under Windows 95.