lib_windows.odin 917 B

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