diff --git a/bindings/java/src/jni/win32/util.c b/bindings/java/src/jni/win32/util.c index a03ffd50..9eacb51a 100644 --- a/bindings/java/src/jni/win32/util.c +++ b/bindings/java/src/jni/win32/util.c @@ -1,6 +1,4 @@ #ifdef WIN32 -#define UNICODE -#define _UNICODE #include #include @@ -22,6 +20,22 @@ void win32_throw_exception(JNIEnv *env, char *msg) JENV->ThrowNew(env, exceptionClass, msg); } +void win32_throw_last_error(JNIEnv *env) +{ + char msg[8192]; + + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + 0, /* default language */ + (LPTSTR)msg, + (DWORD)sizeof(msg), + NULL); + + win32_throw_exception(env, msg); +} + JNIEXPORT jint SIGAR_JNI(win32_Win32_GetLastError) (JNIEnv *env, jclass cls) {