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