factor/native/win32/ffi.c

35 lines
584 B
C
Raw Normal View History

2004-12-17 12:22:16 -05:00
#include "../factor.h"
2005-05-01 18:56:31 -04:00
void init_ffi (void)
{
}
2004-12-26 21:40:45 -05:00
void ffi_dlopen (DLL *dll)
2004-12-17 12:22:16 -05:00
{
HMODULE module;
2005-01-08 16:56:42 -05:00
char *path = to_c_string(untag_string(dll->path));
2004-12-17 12:22:16 -05:00
2005-01-08 16:56:42 -05:00
module = LoadLibrary(path);
2004-12-17 12:22:16 -05:00
if (!module)
general_error(ERROR_FFI, tag_object(last_error()));
dll->dll = module;
}
2004-12-25 05:49:30 -05:00
void *ffi_dlsym (DLL *dll, F_STRING *symbol)
2004-12-17 12:22:16 -05:00
{
2004-12-25 05:49:30 -05:00
void *sym = GetProcAddress(dll ? (HMODULE)dll->dll : GetModuleHandle(NULL),
to_c_string(symbol));
2004-12-17 12:22:16 -05:00
if (!sym)
general_error(ERROR_FFI, tag_object(last_error()));
2004-12-25 05:49:30 -05:00
return sym;
2004-12-17 12:22:16 -05:00
}
2004-12-25 05:49:30 -05:00
void ffi_dlclose (DLL *dll)
2004-12-17 12:22:16 -05:00
{
FreeLibrary((HMODULE)dll->dll);
dll->dll = NULL;
2004-12-25 05:49:30 -05:00
}