diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-12-08 17:33:30 +0000 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-12-08 17:33:30 +0000 |
| commit | fa89d2775a61b1e6943909ff5c96a1e01892d8c9 (patch) | |
| tree | d4e9fee9e27851a8eccc60913f9de7fe26832bfe /code | |
| parent | 60b6538a7a54d7b2af8142e127116939a7444646 (diff) | |
`build_dll`; Require an entry point procedure `main`
Diffstat (limited to 'code')
| -rw-r--r-- | code/demo.odin | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/code/demo.odin b/code/demo.odin index ec54c491c..296bbfa6e 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -1,6 +1,29 @@ +#import "win32.odin" #import "fmt.odin" + main :: proc() { + get_proc :: proc(lib: win32.HMODULE, name: string) -> proc() { + buf: [4096]byte + copy(buf[:], name as []byte) -} + proc_handle := win32.GetProcAddress(lib, ^buf[0]) + return proc_handle as proc() + } + + lib := win32.LoadLibraryA(("example.dll\x00" as string).data) + if lib == nil { + fmt.println("Could not load library") + return + } + defer win32.FreeLibrary(lib) + proc_handle := get_proc(lib, "some_thing") + if proc_handle == nil { + fmt.println("Could not load 'some_thing'") + return + } + + some_thing := (proc_handle as proc()) + some_thing() +} |