factor/native/win32/ffi.c

45 lines
687 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)
{
}
void ffi_dlopen (DLL *dll, bool error)
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)
{
if(error)
general_error(ERROR_FFI, tag_object(last_error()));
else
return;
}
2004-12-17 12:22:16 -05:00
dll->dll = module;
}
void *ffi_dlsym (DLL *dll, F_STRING *symbol, bool error)
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)
{
if(error)
general_error(ERROR_FFI, tag_object(last_error()));
else
return NULL;
}
2004-12-17 12:22:16 -05:00
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
}