v / vlib / dl
Raw file | 43 loc (35 sloc) | 1.25 KB | Latest commit hash e70848a98
1module dl
2
3pub 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
12fn C.LoadLibrary(libfilename &u16) voidptr
13
14fn C.GetProcAddress(handle voidptr, procname &u8) voidptr
15
16fn C.FreeLibrary(handle voidptr) bool
17
18// open loads a given module into the address space of the calling process.
19pub 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.
25pub 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.
30pub 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()
38pub 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}