throw exceptions in jni, GetLastError may have changed by the time it returns to java land

This commit is contained in:
Doug MacEachern 2005-06-26 22:04:32 +00:00
parent c74f93fdea
commit 1ce84e00fc
2 changed files with 7 additions and 12 deletions

View File

@ -63,8 +63,8 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_CloseServiceHandle)
return CloseServiceHandle((SC_HANDLE)handle); return CloseServiceHandle((SC_HANDLE)handle);
} }
JNIEXPORT jint SIGAR_JNI(win32_Service_ControlService) JNIEXPORT void SIGAR_JNI(win32_Service_ControlService)
(JNIEnv *, jclass, jlong handle, jint control) (JNIEnv *env, jclass, jlong handle, jint control)
{ {
BOOL retval; BOOL retval;
SERVICE_STATUS status; SERVICE_STATUS status;
@ -74,11 +74,8 @@ JNIEXPORT jint SIGAR_JNI(win32_Service_ControlService)
else { else {
retval = ControlService((SC_HANDLE)handle, control, &status); retval = ControlService((SC_HANDLE)handle, control, &status);
} }
if (retval) { if (!retval) {
return ERROR_SUCCESS; win32_throw_last_error(env);
}
else {
return GetLastError();
} }
} }

View File

@ -172,9 +172,7 @@ public class Service extends Win32 {
} }
private void control(int ctl) throws Win32Exception { private void control(int ctl) throws Win32Exception {
if (ControlService(this.service, ctl) != SUCCESS) { ControlService(this.service, ctl);
throw new Win32Exception(GetErrorMessage(ctl));
}
} }
private static class Waiter { private static class Waiter {
@ -279,8 +277,8 @@ public class Service extends Win32 {
String startName, String startName,
String password) throws Win32Exception; String password) throws Win32Exception;
private static native int ControlService(long handle, private static native void ControlService(long handle,
int control); int control) throws Win32Exception;
private static native boolean DeleteService(long handle); private static native boolean DeleteService(long handle);