build_dll; Require an entry point procedure main

This commit is contained in:
Ginger Bill
2016-12-08 17:33:30 +00:00
parent 60b6538a7a
commit fa89d2775a
17 changed files with 256 additions and 117 deletions
+24 -1
View File
@@ -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()
}