mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Fix procedure casting; SUBSYSTEM to CONSOLE in linker
This commit is contained in:
+38
-14
@@ -1,31 +1,55 @@
|
|||||||
#import "win32.odin"
|
#import "win32.odin"
|
||||||
#import "fmt.odin"
|
#import "fmt.odin"
|
||||||
|
|
||||||
|
Dll :: struct {
|
||||||
|
Handle :: type rawptr
|
||||||
|
name: string
|
||||||
|
handle: Handle
|
||||||
|
}
|
||||||
|
|
||||||
|
load_library :: proc(name: string) -> (Dll, bool) {
|
||||||
|
buf: [4096]byte
|
||||||
|
copy(buf[:], name as []byte)
|
||||||
|
|
||||||
|
lib := win32.LoadLibraryA(^buf[0])
|
||||||
|
if lib == nil {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
return Dll{name, lib as Dll.Handle}, true
|
||||||
|
}
|
||||||
|
|
||||||
|
free_library :: proc(dll: Dll) {
|
||||||
|
win32.FreeLibrary(dll.handle as win32.HMODULE)
|
||||||
|
}
|
||||||
|
|
||||||
|
get_proc_address :: proc(dll: Dll, name: string) -> (rawptr, bool) {
|
||||||
|
buf: [4096]byte
|
||||||
|
copy(buf[:], name as []byte)
|
||||||
|
|
||||||
|
addr := win32.GetProcAddress(dll.handle as win32.HMODULE, ^buf[0]) as rawptr
|
||||||
|
if addr == nil {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
return addr, true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
get_proc :: proc(lib: win32.HMODULE, name: string) -> proc() {
|
lib, lib_ok := load_library("example.dll")
|
||||||
buf: [4096]byte
|
if !lib_ok {
|
||||||
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")
|
fmt.println("Could not load library")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer win32.FreeLibrary(lib)
|
defer free_library(lib)
|
||||||
|
|
||||||
|
|
||||||
proc_handle := get_proc(lib, "some_thing")
|
proc_addr, addr_ok := get_proc_address(lib, "some_thing")
|
||||||
if proc_handle == nil {
|
if !addr_ok {
|
||||||
fmt.println("Could not load 'some_thing'")
|
fmt.println("Could not load 'some_thing'")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
some_thing := (proc_handle as proc())
|
some_thing := (proc_addr as proc())
|
||||||
fmt.println(some_thing)
|
fmt.println(some_thing)
|
||||||
some_thing()
|
some_thing()
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -245,7 +245,7 @@ StretchDIBits :: proc(hdc: HDC,
|
|||||||
|
|
||||||
LoadLibraryA :: proc(c_str: ^u8) -> HMODULE #foreign
|
LoadLibraryA :: proc(c_str: ^u8) -> HMODULE #foreign
|
||||||
FreeLibrary :: proc(h: HMODULE) #foreign
|
FreeLibrary :: proc(h: HMODULE) #foreign
|
||||||
GetProcAddress :: proc(h: HMODULE, c_str: ^u8) -> proc() #foreign
|
GetProcAddress :: proc(h: HMODULE, c_str: ^u8) -> rawptr #foreign
|
||||||
|
|
||||||
GetClientRect :: proc(hwnd: HWND, rect: ^RECT) -> BOOL #foreign
|
GetClientRect :: proc(hwnd: HWND, rect: ^RECT) -> BOOL #foreign
|
||||||
|
|
||||||
|
|||||||
@@ -1880,6 +1880,10 @@ bool check_is_castable_to(Checker *c, Operand *operand, Type *y) {
|
|||||||
if (is_type_proc(xb) && is_type_rawptr(yb)) {
|
if (is_type_proc(xb) && is_type_rawptr(yb)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// rawptr -> proc
|
||||||
|
if (is_type_rawptr(xb) && is_type_proc(yb)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -232,7 +232,7 @@ int main(int argc, char **argv) {
|
|||||||
exit_code = win32_exec_command_line_app("msvc-link", true,
|
exit_code = win32_exec_command_line_app("msvc-link", true,
|
||||||
"link %.*s.obj -OUT:%.*s.%s %s "
|
"link %.*s.obj -OUT:%.*s.%s %s "
|
||||||
"/defaultlib:libcmt "
|
"/defaultlib:libcmt "
|
||||||
"/nologo /incremental:no /opt:ref /subsystem:WINDOWS "
|
"/nologo /incremental:no /opt:ref /subsystem:CONSOLE "
|
||||||
" %.*s "
|
" %.*s "
|
||||||
" %s "
|
" %s "
|
||||||
"",
|
"",
|
||||||
|
|||||||
Reference in New Issue
Block a user