2020-04-28 12:53:55 +03:00
|
|
|
module dl
|
|
|
|
|
2022-01-05 19:06:08 +03:00
|
|
|
pub const rtld_now = 0
|
|
|
|
|
|
|
|
pub const rtld_lazy = 0
|
2020-04-28 12:53:55 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.LoadLibrary(libfilename &u16) voidptr
|
2020-04-28 12:53:55 +03:00
|
|
|
|
2022-04-15 18:25:45 +03:00
|
|
|
fn C.GetProcAddress(handle voidptr, procname &u8) voidptr
|
2020-04-29 22:01:19 +03:00
|
|
|
|
|
|
|
fn C.FreeLibrary(handle voidptr) bool
|
|
|
|
|
|
|
|
// open loads a given module into the address space of the calling process.
|
2020-04-28 12:53:55 +03:00
|
|
|
pub fn open(filename string, flags int) voidptr {
|
2020-04-29 22:01:19 +03:00
|
|
|
res := C.LoadLibrary(filename.to_wide())
|
2020-04-28 12:53:55 +03:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2020-04-29 22:01:19 +03:00
|
|
|
// close frees the loaded a given module.
|
|
|
|
pub fn close(handle voidptr) bool {
|
|
|
|
return C.FreeLibrary(handle)
|
|
|
|
}
|
|
|
|
|
|
|
|
// sym returns an address of an exported function or variable from a given module.
|
2020-04-28 12:53:55 +03:00
|
|
|
pub fn sym(handle voidptr, symbol string) voidptr {
|
|
|
|
return C.GetProcAddress(handle, symbol.str)
|
|
|
|
}
|
2021-03-24 12:47:04 +03:00
|
|
|
|
|
|
|
// dlerror provides a text error diagnostic message for functions in `dl`
|
2021-04-07 16:25:11 +03:00
|
|
|
// it returns a human-readable string, describing the most recent error
|
2021-03-24 12:47:04 +03:00
|
|
|
// that occurred from a call to one of the `dl` functions, since the last
|
|
|
|
// call to dlerror()
|
|
|
|
pub fn dlerror() string {
|
|
|
|
// https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror
|
|
|
|
// Unlike dlerror(), GetLastError returns just an error code, that is function specific.
|
|
|
|
cerr := int(C.GetLastError())
|
2022-11-15 16:53:13 +03:00
|
|
|
return 'error code ${cerr}'
|
2021-03-24 12:47:04 +03:00
|
|
|
}
|