diff --git a/native/misc.c b/native/misc.c index b553224e77..4234f2a3e3 100644 --- a/native/misc.c +++ b/native/misc.c @@ -68,17 +68,22 @@ char *buffer_to_c_string(char *buffer) return (char*)c_str; } -char *last_error() +F_STRING *get_error_message() +{ + DWORD id = GetLastError(); + return from_c_string(error_message(id)); +} + +char *error_message(DWORD id) { char *buffer; int index; - DWORD dw = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, - dw, + id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buffer, 0, NULL); diff --git a/native/misc.h b/native/misc.h index 05aab9f434..c7fd2f8e41 100644 --- a/native/misc.h +++ b/native/misc.h @@ -6,6 +6,7 @@ void primitive_millis(void); void primitive_random_int(void); #ifdef WIN32 char *buffer_to_c_string(char *buffer); -DLLEXPORT char *last_error(); +F_STRING *get_error_message(); +DLLEXPORT char *error_message(DWORD id); #endif