v/vlib/dl/dl_windows.c.v

40 lines
1.2 KiB
V
Raw Normal View History

2020-04-28 11:53:55 +02:00
module dl
pub const (
2020-12-15 17:55:04 +01:00
rtld_now = 0
2020-05-22 17:36:09 +02:00
rtld_lazy = 0
2020-04-28 11:53:55 +02:00
)
fn C.LoadLibrary(libfilename &u16) voidptr
2020-04-28 11:53:55 +02:00
2021-04-05 19:55:03 +02:00
fn C.GetProcAddress(handle voidptr, procname &byte) voidptr
2020-04-29 21:01:19 +02:00
fn C.FreeLibrary(handle voidptr) bool
// open loads a given module into the address space of the calling process.
2020-04-28 11:53:55 +02:00
pub fn open(filename string, flags int) voidptr {
2020-04-29 21:01:19 +02:00
res := C.LoadLibrary(filename.to_wide())
2020-04-28 11:53:55 +02:00
return res
}
2020-04-29 21:01:19 +02: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 11:53:55 +02:00
pub fn sym(handle voidptr, symbol string) voidptr {
return C.GetProcAddress(handle, symbol.str)
}
// dlerror provides a text error diagnostic message for functions in `dl`
// it returns a human-readable string, describing the most recent error
// 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())
return 'error code $cerr'
}