lib_windows.odin 805 B

1234567891011121314151617181920212223242526
  1. //+build windows
  2. //+private
  3. package dynlib
  4. import win32 "core:sys/windows"
  5. import "core:strings"
  6. _load_library :: proc(path: string, global_symbols := false) -> (Library, bool) {
  7. // NOTE(bill): 'global_symbols' is here only for consistency with POSIX which has RTLD_GLOBAL
  8. wide_path := win32.utf8_to_wstring(path, context.temp_allocator)
  9. handle := cast(Library)win32.LoadLibraryW(wide_path)
  10. return handle, handle != nil
  11. }
  12. _unload_library :: proc(library: Library) -> bool {
  13. ok := win32.FreeLibrary(cast(win32.HMODULE)library)
  14. return bool(ok)
  15. }
  16. _symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) {
  17. c_str := strings.clone_to_cstring(symbol, context.temp_allocator)
  18. ptr = win32.GetProcAddress(cast(win32.HMODULE)library, c_str)
  19. found = ptr != nil
  20. return
  21. }