add function to throw exception w/ FormatMessage of GetLastError()

This commit is contained in:
Doug MacEachern 2005-06-26 21:06:03 +00:00
parent 01f5cb6c9e
commit 150c4c5e9c
1 changed files with 16 additions and 2 deletions

View File

@ -1,6 +1,4 @@
#ifdef WIN32 #ifdef WIN32
#define UNICODE
#define _UNICODE
#include <pdh.h> #include <pdh.h>
#include <pdhmsg.h> #include <pdhmsg.h>
@ -22,6 +20,22 @@ void win32_throw_exception(JNIEnv *env, char *msg)
JENV->ThrowNew(env, exceptionClass, 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) JNIEXPORT jint SIGAR_JNI(win32_Win32_GetLastError)
(JNIEnv *env, jclass cls) (JNIEnv *env, jclass cls)
{ {