Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2006-04-03 10:12:04 -0400
committerDoug Schaefer2006-04-03 10:12:04 -0400
commit0c247b1d5f7b8f8e5b0d5bd7cd09239334877b30 (patch)
tree5f378655fc71e3f29b7815aba62ab5e87924730f /core/org.eclipse.cdt.core.win32/library
parent3df6744baa967bdb53c8d52fe2a7ce47e4cd2f10 (diff)
downloadorg.eclipse.cdt-0c247b1d5f7b8f8e5b0d5bd7cd09239334877b30.tar.gz
org.eclipse.cdt-0c247b1d5f7b8f8e5b0d5bd7cd09239334877b30.tar.xz
org.eclipse.cdt-0c247b1d5f7b8f8e5b0d5bd7cd09239334877b30.zip
Make the Windows registry code a little more robust.
Diffstat (limited to 'core/org.eclipse.cdt.core.win32/library')
-rw-r--r--core/org.eclipse.cdt.core.win32/library/winreg.cpp31
1 files changed, 4 insertions, 27 deletions
diff --git a/core/org.eclipse.cdt.core.win32/library/winreg.cpp b/core/org.eclipse.cdt.core.win32/library/winreg.cpp
index 3f892b95fa..8b0562ae7f 100644
--- a/core/org.eclipse.cdt.core.win32/library/winreg.cpp
+++ b/core/org.eclipse.cdt.core.win32/library/winreg.cpp
@@ -2,48 +2,25 @@
#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;
+ jstring result = NULL;
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 {
+ if (rc == ERROR_SUCCESS) {
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 {
+ if (rc == ERROR_SUCCESS) {
result = env->NewString((jchar *)buffer, wcslen(buffer));
}
+ RegCloseKey(key);
}
env->ReleaseStringChars(subkey, csubkey);

Back to the top