Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2006-04-03 05:41:36 +0000
committerDoug Schaefer2006-04-03 05:41:36 +0000
commit84cef01e4612302e984862c5c91d07b8073fbb33 (patch)
tree394cf337dc511e2f7cf1937cacba9fbe8bebe96d /core/org.eclipse.cdt.core.win32
parentf4e3af2a4e99d18fb90205f7367ac02f86c3e211 (diff)
downloadorg.eclipse.cdt-84cef01e4612302e984862c5c91d07b8073fbb33.tar.gz
org.eclipse.cdt-84cef01e4612302e984862c5c91d07b8073fbb33.tar.xz
org.eclipse.cdt-84cef01e4612302e984862c5c91d07b8073fbb33.zip
Windows registry access utility.
Diffstat (limited to 'core/org.eclipse.cdt.core.win32')
-rw-r--r--core/org.eclipse.cdt.core.win32/library/nmake.mak8
-rw-r--r--core/org.eclipse.cdt.core.win32/library/winreg.cpp53
-rw-r--r--core/org.eclipse.cdt.core.win32/os/win32/x86/.cvsignore2
-rw-r--r--core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dllbin0 -> 49152 bytes
4 files changed, 63 insertions, 0 deletions
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 <windows.h>
+#include <jni.h>
+#include <string.h>
+
+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
--- /dev/null
+++ b/core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dll
Binary files differ

Back to the top