The java.util.prefs.WindowsPreferences is the concrete implementation of AbstractPreferences in the Windows platform. This class provides methods like WindowsRegQueryValueEx, etc. Using Reflection, one can use the methods in this class to query string values under HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER. For some reason, the java wrapper for WindowsRegQueryValueEx only seems to work for string values. I get a null for values of type REG_DWORD, which I guess makes this approach pretty useless except in times of desperation. Please Tell me how I can retrive REG_DWORD values.
Don't count on classes not in the public API. They may disappear or change at any time. This includes WindowsPreferences because it's not public.
The Windows native call RegQueryValueEx returns the actual type in its fourth parameter. This call has 6 parameters. In contract, the Java method WindowsRegQueryValueEx only has 2 parameters - the key and the name (as a byte[]). So, Sun discard the actual type at this point. I've checked the source of WindowsPreferences some more, and it totally ignores the possible type - it just treats the byte[] returned by the method as a String. I recon WindowsRegQueryValueEx returns null if the actual registry value type is not a string. This makes me believe that WindowsPreferences convert any input to and from REG_SZ (stirng).
Rob Prime wrote:Don't count on classes not in the public API. They may disappear or change at any time. This includes WindowsPreferences because it's not public.
The Windows native call RegQueryValueEx returns the actual type in its fourth parameter. This call has 6 parameters. In contract, the Java method WindowsRegQueryValueEx only has 2 parameters - the key and the name (as a byte[]). So, Sun discard the actual type at this point. I've checked the source of WindowsPreferences some more, and it totally ignores the possible type - it just treats the byte[] returned by the method as a String. I recon WindowsRegQueryValueEx returns null if the actual registry value type is not a string. This makes me believe that WindowsPreferences convert any input to and from REG_SZ (stirng).
manjula sharma wrote:which one download from page: http://www.gjt.org/download/ to get thired party registry library that uses JNI?
Are you asking how to find the string "JNIRegistry" -which Rob mentioned was the project's name- on that page?
I am using java.util.pref.WindowsPreferences to read windows registry values.
but it returns NULL for all key value data which is not of type String.
(Same problem as posted at the top of this page)
Is there anyother JNI to solve the issue, where to download it??