diff --git a/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp b/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp index 81367b9e47c..c10d37a253e 100644 --- a/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp +++ b/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp @@ -78,3 +78,43 @@ JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMac return result; } + +/* + * Given a subkey (string) under HKEY_LOCAL_MACHINE, and an index (starting from 0) + * to the key's array of keys, return the name of the indexed key. + * The return value is null on any error or when the index is invalid. + */ + +extern "C" +JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineKeyName( + JNIEnv * env, jobject obj, jstring subkey, jint index) +{ + const jchar * csubkey = env->GetStringChars(subkey, NULL); + jstring result = NULL; + + HKEY key; + LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (const wchar_t *)csubkey, 0, KEY_READ, &key); + if (rc != ERROR_SUCCESS) + return NULL; + + wchar_t keyName[256]; + DWORD nameSize = sizeof(keyName) + 2; + + rc = RegEnumKeyEx(key, index, + keyName, // UNICODE string + &nameSize, + NULL, NULL, + NULL, + NULL); // size in BYTE of data. + + if (rc == ERROR_SUCCESS) + { + result = env->NewString((jchar *)keyName, nameSize); + } + + RegCloseKey(key); + + env->ReleaseStringChars(subkey, csubkey); + + return result; +} diff --git a/core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dll b/core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dll index 771e5e7598a..0d613301f7a 100644 Binary files a/core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dll and b/core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dll differ diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/WindowsRegistry.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/WindowsRegistry.java index 31e6eeda69d..ce05a273be4 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/WindowsRegistry.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/WindowsRegistry.java @@ -65,5 +65,17 @@ public class WindowsRegistry { * @return name of registry value or null if not found */ public native String getLocalMachineValueName(String subkey, int index); + + /** + * Given a subkey of HKEY_LOCAL_MACHINE, and an index (starting from 0) + * to the key's array of sub keys, return the name of the indexed key. + * The return value is null on any error or when the index is invalid. + * The key name can be used in the above getLocalMachineValueName() + * to retrieve value names. + * @param subkey subkey of HKEY_LOCAL_MACHINE + * @param index index to the subkey's array of values, starting from 0. + * @return name of registry value or null if not found + */ + public native String getLocalMachineKeyName(String subkey, int index); }