lib_windows.odin 780 B

123456789101112131415161718192021222324
  1. package dynlib
  2. import "core:sys/win32"
  3. import "core:strings"
  4. load_library :: proc(path: string, global_symbols := false) -> (Library, bool) {
  5. // NOTE(bill): 'global_symbols' is here only for consistency with POSIX which has RTLD_GLOBAL
  6. wide_path := win32.utf8_to_wstring(path, context.temp_allocator);
  7. handle := cast(Library)win32.load_library_w(wide_path);
  8. return handle, handle != nil;
  9. }
  10. unload_library :: proc(library: Library) -> bool {
  11. ok := win32.free_library(cast(win32.Hmodule)library);
  12. return bool(ok);
  13. }
  14. symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) {
  15. c_str := strings.clone_to_cstring(symbol, context.temp_allocator);
  16. ptr = win32.get_proc_address(cast(win32.Hmodule)library, c_str);
  17. found = ptr != nil;
  18. return;
  19. }