<commit_before>#ifdef WIN32
#define UNICODE
#define _UNICODE

#include <pdh.h>
#include <pdhmsg.h>

#include "win32bindings.h"
#include "javasigar.h"

/**
 * Set of common utilities for all win32bindings objects
 */

#ifdef __cplusplus
extern "C" {
#endif

void win32_throw_exception(JNIEnv *env, char *msg)
{
    jclass exceptionClass = WIN32_FIND_CLASS("Win32Exception");
    JENV->ThrowNew(env, exceptionClass, msg);
}

JNIEXPORT jint SIGAR_JNI(win32_Win32_GetLastError)
(JNIEnv *env, jclass cls)
{
    return GetLastError();
}

JNIEXPORT jstring SIGAR_JNI(win32_Win32_GetErrorMessage)
(JNIEnv *env, jclass cls, jint error)
{
    LPTSTR msg;
    jstring str;

    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
                  FORMAT_MESSAGE_IGNORE_INSERTS|
                  FORMAT_MESSAGE_FROM_SYSTEM,
                  NULL, error, 
                  MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
                  (LPTSTR)&msg, 0, NULL);
    str = JENV->NewString(env, (const jchar *)msg, lstrlen(msg));
    LocalFree(msg);
    return str;
}

#ifdef __cplusplus<commit_msg>add function to throw exception w/ FormatMessage of GetLastError()<commit_after>#ifdef WIN32

#include <pdh.h>
#include <pdhmsg.h>

#include "win32bindings.h"
#include "javasigar.h"

/**
 * Set of common utilities for all win32bindings objects
 */

#ifdef __cplusplus
extern "C" {
#endif

void win32_throw_exception(JNIEnv *env, char *msg)
{
    jclass exceptionClass = WIN32_FIND_CLASS("Win32Exception");
    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)
{
    return GetLastError();
}

JNIEXPORT jstring SIGAR_JNI(win32_Win32_GetErrorMessage)
(JNIEnv *env, jclass cls, jint error)
{
    LPTSTR msg;
    jstring str;

    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
                  FORMAT_MESSAGE_IGNORE_INSERTS|
                  FORMAT_MESSAGE_FROM_SYSTEM,
                  NULL, error, 
                  MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
                  (LPTSTR)&msg, 0, NULL);
    str = JENV->NewString(env, (const jchar *)msg, lstrlen(msg));
    LocalFree(msg);
    return str;
}

#ifdef __cplusplus
{'fraction_non_alphanumeric': 0.09887553315238465, 'fraction_numerical': 0.019775106630476928, 'mean_word_length': 2.987635239567233, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '953450', 'n_tokens_mistral': 947, 'n_tokens_neox': 887, 'n_words': 182}