From 1ce84e00fc233364dd9088d0ba61aa9dcc986398 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 26 Jun 2005 22:04:32 +0000 Subject: [PATCH] throw exceptions in jni, GetLastError may have changed by the time it returns to java land --- bindings/java/src/jni/win32/service.cpp | 11 ++++------- .../java/src/net/hyperic/sigar/win32/Service.java | 8 +++----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/bindings/java/src/jni/win32/service.cpp b/bindings/java/src/jni/win32/service.cpp index 7e3d1b05..e5b72772 100644 --- a/bindings/java/src/jni/win32/service.cpp +++ b/bindings/java/src/jni/win32/service.cpp @@ -63,8 +63,8 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_CloseServiceHandle) return CloseServiceHandle((SC_HANDLE)handle); } -JNIEXPORT jint SIGAR_JNI(win32_Service_ControlService) -(JNIEnv *, jclass, jlong handle, jint control) +JNIEXPORT void SIGAR_JNI(win32_Service_ControlService) +(JNIEnv *env, jclass, jlong handle, jint control) { BOOL retval; SERVICE_STATUS status; @@ -74,11 +74,8 @@ JNIEXPORT jint SIGAR_JNI(win32_Service_ControlService) else { retval = ControlService((SC_HANDLE)handle, control, &status); } - if (retval) { - return ERROR_SUCCESS; - } - else { - return GetLastError(); + if (!retval) { + win32_throw_last_error(env); } } diff --git a/bindings/java/src/net/hyperic/sigar/win32/Service.java b/bindings/java/src/net/hyperic/sigar/win32/Service.java index 92ea307d..b06c4c50 100644 --- a/bindings/java/src/net/hyperic/sigar/win32/Service.java +++ b/bindings/java/src/net/hyperic/sigar/win32/Service.java @@ -172,9 +172,7 @@ public class Service extends Win32 { } private void control(int ctl) throws Win32Exception { - if (ControlService(this.service, ctl) != SUCCESS) { - throw new Win32Exception(GetErrorMessage(ctl)); - } + ControlService(this.service, ctl); } private static class Waiter { @@ -279,8 +277,8 @@ public class Service extends Win32 { String startName, String password) throws Win32Exception; - private static native int ControlService(long handle, - int control); + private static native void ControlService(long handle, + int control) throws Win32Exception; private static native boolean DeleteService(long handle);