dynlib: add last_error procedure

This commit is contained in:
Laytan Laats
2024-01-06 02:08:11 +01:00
parent 649b5fa528
commit 85b71708dd
4 changed files with 33 additions and 2 deletions
+7
View File
@@ -5,6 +5,7 @@ package dynlib
import win32 "core:sys/windows"
import "core:strings"
import "core:runtime"
import "core:reflect"
_load_library :: proc(path: string, global_symbols := false) -> (Library, bool) {
// NOTE(bill): 'global_symbols' is here only for consistency with POSIX which has RTLD_GLOBAL
@@ -27,3 +28,9 @@ _symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found
found = ptr != nil
return
}
_last_error :: proc() -> string {
err := win32.System_Error(win32.GetLastError())
err_msg := reflect.enum_string(err)
return "unknown" if err_msg == "" else err_msg
}