v2 / vlib / dl / dl_windows.c.v
45 lines · 35 sloc · 1.34 KB · 3271c728d53ea7eb66a03523b82b951acf80bb19
Raw
1module dl
2
3pub const rtld_now = 0
4pub const rtld_lazy = 0
5pub const rtld_global = 0
6pub const rtld_local = 0
7pub const rtld_nodelete = 0
8pub const rtld_noload = 0
9
10fn C.LoadLibrary(libfilename &u16) voidptr
11
12fn C.GetProcAddress(handle voidptr, procname &u8) voidptr
13
14fn C.FreeLibrary(handle voidptr) bool
15
16type FN_vinit_caller = fn ()
17
18type FN_vcleanup_caller = fn ()
19
20// open loads a given module into the address space of the calling process.
21pub 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.
27pub 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.
32pub 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().
40pub 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