From 61327b9034cdea3466b3d3222ad59247f5038b89 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 12 Sep 2008 05:14:40 +0000 Subject: [PATCH] [SIGAR-120] Support WoW registry reflection --- bindings/java/src/jni/win32/registrykey.cpp | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bindings/java/src/jni/win32/registrykey.cpp b/bindings/java/src/jni/win32/registrykey.cpp index 9e810f18..7b3e378c 100644 --- a/bindings/java/src/jni/win32/registrykey.cpp +++ b/bindings/java/src/jni/win32/registrykey.cpp @@ -106,6 +106,19 @@ JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegLoadKey) return lResult; } +/* http://msdn.microsoft.com/en-us/library/aa384129(VS.85).aspx */ +#ifndef KEY_WOW64_64KEY +#define KEY_WOW64_64KEY 0x0100 +#endif +#ifndef KEY_WOW64_32KEY +#define KEY_WOW64_32KEY 0x0200 +#endif + +static DWORD RegOpenOpts[] = { + KEY_WOW64_32KEY, + KEY_WOW64_64KEY +}; + JNIEXPORT jlong SIGAR_JNI(win32_RegistryKey_RegOpenKey) (JNIEnv *env, jclass, jlong hkey, jstring subkey) { @@ -113,6 +126,7 @@ JNIEXPORT jlong SIGAR_JNI(win32_RegistryKey_RegOpenKey) jsize len = env->GetStringLength(subkey); LPTSTR lpSubkey = (LPTSTR)env->GetStringChars(subkey, NULL); LPTSTR copy; + int i; /* required under IBM/WebSphere 4.0 for certain keys */ if (lpSubkey[len] != '\0') { @@ -122,7 +136,18 @@ JNIEXPORT jlong SIGAR_JNI(win32_RegistryKey_RegOpenKey) else { copy = lpSubkey; } - RegOpenKey((HKEY)hkey, copy, &hkeyResult); + + /* try both flags so 32-bit apps can access registry entries + of 64-bit apps and vice-versa */ + for (i=0; iReleaseStringChars(subkey, (const jchar *)lpSubkey); if (copy != lpSubkey) {