From f5c4671bfbad96bf346bd7e9a21fc4317b4959df Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Sat, 3 Dec 2022 17:00:20 +0530 Subject: Adds most of the tools --- v_windows/v/vlib/dl/dl_windows.c.v | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 v_windows/v/vlib/dl/dl_windows.c.v (limited to 'v_windows/v/vlib/dl/dl_windows.c.v') diff --git a/v_windows/v/vlib/dl/dl_windows.c.v b/v_windows/v/vlib/dl/dl_windows.c.v new file mode 100644 index 0000000..b6ae2fc --- /dev/null +++ b/v_windows/v/vlib/dl/dl_windows.c.v @@ -0,0 +1,39 @@ +module dl + +pub const ( + rtld_now = 0 + rtld_lazy = 0 +) + +fn C.LoadLibrary(libfilename &u16) voidptr + +fn C.GetProcAddress(handle voidptr, procname &byte) voidptr + +fn C.FreeLibrary(handle voidptr) bool + +// open loads a given module into the address space of the calling process. +pub fn open(filename string, flags int) voidptr { + res := C.LoadLibrary(filename.to_wide()) + return res +} + +// 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. +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' +} -- cgit v1.2.3