lib_windows.odin 792 B

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