From 150c4c5e9c89a3be5d9bb770429b99b60187eb9e Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 26 Jun 2005 21:06:03 +0000 Subject: [PATCH] add function to throw exception w/ FormatMessage of GetLastError() --- bindings/java/src/jni/win32/util.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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) {