Windows 95 RegOpenKeyEx Incompatible with Windows NTID: Q137202
|
A Win32-based application runs under Windows 95 but does not run correctly under Windows NT. Or a Windows-based application runs under Windows 95 but leaks registry handles under Windows NT.
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)
RegOpenKey(OldKey, NULL, 0, MAXIMUM_ALLOWED, &NewKey)
RegCloseKey(OldKey)
RegQueryValue(NewKey,...)
RegCloseKey(NewKey)
You should use RegOpenKeyEx and make sure that there is a corresponding close call for each open call. This will ensure that you do not use any handle that has been closed.
This behavior is by design.
Additional query words: 4.00 Windows win95fest
Keywords : kbKernBase kbRegistry kbGrpKernBase
Version : 4.00
Platform : WINDOWS
Issue type :
Last Reviewed: March 7, 1999