From 84cef01e4612302e984862c5c91d07b8073fbb33 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Mon, 3 Apr 2006 05:41:36 +0000 Subject: Windows registry access utility. --- core/org.eclipse.cdt.core.win32/library/nmake.mak | 8 ++++ core/org.eclipse.cdt.core.win32/library/winreg.cpp | 53 +++++++++++++++++++++ .../os/win32/x86/.cvsignore | 2 + .../os/win32/x86/winreg.dll | Bin 0 -> 49152 bytes 4 files changed, 63 insertions(+) create mode 100644 core/org.eclipse.cdt.core.win32/library/nmake.mak create mode 100644 core/org.eclipse.cdt.core.win32/library/winreg.cpp create mode 100644 core/org.eclipse.cdt.core.win32/os/win32/x86/.cvsignore create mode 100644 core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dll (limited to 'core/org.eclipse.cdt.core.win32') diff --git a/core/org.eclipse.cdt.core.win32/library/nmake.mak b/core/org.eclipse.cdt.core.win32/library/nmake.mak new file mode 100644 index 00000000000..a3ce6c74cc8 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/nmake.mak @@ -0,0 +1,8 @@ +TARGET = ..\os\win32\x86\winreg.dll + +OBJS = winreg.obj + +CPPFLAGS = /nologo /I C:\Java\jdk1.5.0_06\include /I C:\Java\jdk1.5.0_06\include\win32 /DUNICODE + +$(TARGET): $(OBJS) + link /nologo /dll /out:$(TARGET) $(OBJS) advapi32.lib user32.lib diff --git a/core/org.eclipse.cdt.core.win32/library/winreg.cpp b/core/org.eclipse.cdt.core.win32/library/winreg.cpp new file mode 100644 index 00000000000..3f892b95fa7 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/winreg.cpp @@ -0,0 +1,53 @@ +#include +#include +#include + +jstring getErrorMsg(JNIEnv * env, wchar_t * name) { + wchar_t msg[256]; + wchar_t * msgBuff; + DWORD err = GetLastError(); + + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + err, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &msgBuff, + 0, NULL ); + + wsprintf(msg, L"%s failed with error %d: %s", name, err, msgBuff); + + LocalFree(msgBuff); + + return env->NewString((jchar *)msg, wcslen(msg)); +} + +extern "C" +JNIEXPORT jstring Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineValue( + JNIEnv * env, jobject obj, jstring subkey, jstring name) +{ + const jchar * csubkey = env->GetStringChars(subkey, NULL); + const jchar * cname = env->GetStringChars(name, NULL); + jstring result; + + HKEY key; + LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (const wchar_t *)csubkey, 0, KEY_READ, &key); + if (rc != ERROR_SUCCESS) { + result = getErrorMsg(env, L"RegOpenKeyEx"); + } else { + DWORD type; + wchar_t buffer[256]; + DWORD len = sizeof(buffer); + rc = RegQueryValueEx(key, (const wchar_t *)cname, NULL, &type, (BYTE *)&buffer, &len); + if (rc != ERROR_SUCCESS) { + result = getErrorMsg(env, L"RegQueryValueEx"); + } else { + result = env->NewString((jchar *)buffer, wcslen(buffer)); + } + } + + env->ReleaseStringChars(subkey, csubkey); + env->ReleaseStringChars(name, cname); + + return result; +} diff --git a/core/org.eclipse.cdt.core.win32/os/win32/x86/.cvsignore b/core/org.eclipse.cdt.core.win32/os/win32/x86/.cvsignore new file mode 100644 index 00000000000..d3879971eec --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/os/win32/x86/.cvsignore @@ -0,0 +1,2 @@ +winreg.lib +winreg.exp 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 new file mode 100644 index 00000000000..2c113d73d3f Binary files /dev/null and b/core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dll differ -- cgit v1.2.3