diff --git a/core/dynlib/lib.odin b/core/dynlib/lib.odin new file mode 100644 index 000000000..66742b835 --- /dev/null +++ b/core/dynlib/lib.odin @@ -0,0 +1,3 @@ +package dynlib + +Library :: opaque rawptr; diff --git a/core/dynlib/lib_windows.odin b/core/dynlib/lib_windows.odin new file mode 100644 index 000000000..67ce47cc1 --- /dev/null +++ b/core/dynlib/lib_windows.odin @@ -0,0 +1,24 @@ +package dynlib + +import "core:sys/win32" +import "core:strings" + +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 + + wide_path := win32.utf8_to_wstring(path, context.temp_allocator); + handle := cast(Library)win32.load_library_w(wide_path); + return handle, handle != nil; +} + +unload_library :: proc(library: Library) -> bool { + ok := win32.free_library(cast(win32.Hmodule)library); + return bool(ok); +} + +symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) { + c_str := strings.new_cstring(symbol, context.temp_allocator); + ptr = win32.get_proc_address(cast(win32.Hmodule)library, c_str); + found == ptr != nil; + return; +} diff --git a/core/sys/win32/kernel32.odin b/core/sys/win32/kernel32.odin index 6f9390cc4..33ef0e8b7 100644 --- a/core/sys/win32/kernel32.odin +++ b/core/sys/win32/kernel32.odin @@ -164,7 +164,7 @@ foreign kernel32 { @(link_name="LoadLibraryA") load_library_a :: proc(c_str: cstring) -> Hmodule ---; @(link_name="LoadLibraryW") load_library_w :: proc(c_str: Wstring) -> Hmodule ---; - @(link_name="FreeLibrary") free_library :: proc(h: Hmodule) ---; + @(link_name="FreeLibrary") free_library :: proc(h: Hmodule) -> Bool ---; @(link_name="GetProcAddress") get_proc_address :: proc(h: Hmodule, c_str: cstring) -> rawptr ---; } diff --git a/core/unicode/utf8/utf8.odin b/core/unicode/utf8/utf8.odin index 50b33a680..d0396b9e0 100644 --- a/core/unicode/utf8/utf8.odin +++ b/core/unicode/utf8/utf8.odin @@ -90,7 +90,7 @@ encode_rune :: proc(r: rune) -> ([4]u8, int) { buf[0] = 0xf0 | u8(r>>18); buf[1] = 0x80 | u8(r>>12) & mask; buf[2] = 0x80 | u8(r>>6) & mask; - buf[3] = 0x80 | u8(r) & mask; + buf[3] = 0x80 | u8(r) & mask; return buf, 4; }