diff options
| author | Laytan Laats <laytanlaats@hotmail.com> | 2024-11-28 21:05:17 +0100 |
|---|---|---|
| committer | Laytan Laats <laytanlaats@hotmail.com> | 2024-11-28 21:08:08 +0100 |
| commit | 1cece52359ec32d3b82b2f419faceb2e323ee6a1 (patch) | |
| tree | 5c23028e0856415b13ef997d9ba4e77267fc2e05 /core/dynlib/example | |
| parent | 276928170c61653318cb54f00a2162284bd242db (diff) | |
dynlib: unload library before loading again & add LIBRARY_FILE_EXTENSION constant
Diffstat (limited to 'core/dynlib/example')
| -rw-r--r-- | core/dynlib/example/example.odin | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/core/dynlib/example/example.odin b/core/dynlib/example/example.odin index f12233b0a..78fb5a98c 100644 --- a/core/dynlib/example/example.odin +++ b/core/dynlib/example/example.odin @@ -21,12 +21,14 @@ Symbols :: struct { main :: proc() { sym: Symbols + LIB_PATH :: "lib." + dynlib.LIBRARY_FILE_EXTENSION + // Load symbols from `lib.dll` into Symbols struct. // Each struct field is prefixed with `foo_` before lookup in the DLL's symbol table. // The library's Handle (to unload) will be stored in `sym._my_lib_handle`. This way you can load multiple DLLs in one struct. - count, ok := dynlib.initialize_symbols(&sym, "lib.dll", "foo_", "_my_lib_handle") + count, ok := dynlib.initialize_symbols(&sym, LIB_PATH, "foo_", "_my_lib_handle") defer dynlib.unload_library(sym._my_lib_handle) - fmt.printf("(Initial DLL Load) ok: %v. %v symbols loaded from lib.dll (%p).\n", ok, count, sym._my_lib_handle) + fmt.printf("(Initial DLL Load) ok: %v. %v symbols loaded from " + LIB_PATH + " (%p).\n", ok, count, sym._my_lib_handle) if count > 0 { fmt.println("42 + 42 =", sym.add(42, 42)) @@ -34,12 +36,12 @@ main :: proc() { fmt.println("hellope =", sym.hellope^) } - count, ok = dynlib.initialize_symbols(&sym, "lib.dll", "foo_", "_my_lib_handle") - fmt.printf("(DLL Reload) ok: %v. %v symbols loaded from lib.dll (%p).\n", ok, count, sym._my_lib_handle) + count, ok = dynlib.initialize_symbols(&sym, LIB_PATH, "foo_", "_my_lib_handle") + fmt.printf("(DLL Reload) ok: %v. %v symbols loaded from " + LIB_PATH + " (%p).\n", ok, count, sym._my_lib_handle) if count > 0 { fmt.println("42 + 42 =", sym.add(42, 42)) fmt.println("84 - 13 =", sym.sub(84, 13)) fmt.println("hellope =", sym.hellope^) } -}
\ No newline at end of file +} |