1 | module dl |
2 | |
3 | pub const ( |
4 | rtld_now = 0 |
5 | rtld_lazy = 0 |
6 | rtld_global = 0 |
7 | rtld_local = 0 |
8 | rtld_nodelete = 0 |
9 | rtld_noload = 0 |
10 | ) |
11 | |
12 | fn C.LoadLibrary(libfilename &u16) voidptr |
13 | |
14 | fn C.GetProcAddress(handle voidptr, procname &u8) voidptr |
15 | |
16 | fn C.FreeLibrary(handle voidptr) bool |
17 | |
18 | // open loads a given module into the address space of the calling process. |
19 | pub fn open(filename string, flags int) voidptr { |
20 | res := C.LoadLibrary(filename.to_wide()) |
21 | return res |
22 | } |
23 | |
24 | // close frees the loaded a given module. |
25 | pub fn close(handle voidptr) bool { |
26 | return C.FreeLibrary(handle) |
27 | } |
28 | |
29 | // sym returns an address of an exported function or variable from a given module. |
30 | pub fn sym(handle voidptr, symbol string) voidptr { |
31 | return C.GetProcAddress(handle, symbol.str) |
32 | } |
33 | |
34 | // dlerror provides a text error diagnostic message for functions in `dl` |
35 | // it returns a human-readable string, describing the most recent error |
36 | // that occurred from a call to one of the `dl` functions, since the last |
37 | // call to dlerror() |
38 | pub fn dlerror() string { |
39 | // https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror |
40 | // Unlike dlerror(), GetLastError returns just an error code, that is function specific. |
41 | cerr := int(C.GetLastError()) |
42 | return 'error code ${cerr}' |
43 | } |