aboutsummaryrefslogtreecommitdiff
path: root/core/dynlib/example/example.odin
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2024-11-28 21:20:07 +0100
committerGitHub <noreply@github.com>2024-11-28 21:20:07 +0100
commit314c41ef33a2d11e4313ecca0c708b8d02cd59d7 (patch)
tree47745fb861343c0dd491bba88ca196d8d2c282ab /core/dynlib/example/example.odin
parent6d83755e9239ea7e4fb6a24d91c9bd8f4148213b (diff)
parent1cece52359ec32d3b82b2f419faceb2e323ee6a1 (diff)
Merge pull request #4534 from laytan/dynlib-unload-before-load
dynlib: unload library before loading again & add LIBRARY_FILE_EXTENSION constant
Diffstat (limited to 'core/dynlib/example/example.odin')
-rw-r--r--core/dynlib/example/example.odin12
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
+}