2004-12-17 12:22:16 -05:00
|
|
|
#include "../factor.h"
|
|
|
|
|
2005-05-01 18:56:31 -04:00
|
|
|
void init_ffi (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-08-15 15:34:00 -04:00
|
|
|
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)
|
2005-08-15 15:34:00 -04:00
|
|
|
{
|
2005-10-02 15:47:33 -04:00
|
|
|
dll->dll = NULL;
|
2005-08-15 15:34:00 -04:00
|
|
|
if(error)
|
2005-10-07 18:50:31 -04:00
|
|
|
general_error(ERROR_FFI, tag_object(get_error_message()));
|
2005-08-15 15:34:00 -04:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2004-12-17 12:22:16 -05:00
|
|
|
|
|
|
|
dll->dll = module;
|
|
|
|
}
|
|
|
|
|
2005-08-15 15:34:00 -04:00
|
|
|
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)
|
2005-08-15 15:34:00 -04:00
|
|
|
{
|
|
|
|
if(error)
|
2005-10-07 18:50:31 -04:00
|
|
|
general_error(ERROR_FFI, tag_object(get_error_message()));
|
2005-08-15 15:34:00 -04:00
|
|
|
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;
|
2005-10-02 15:47:33 -04:00
|
|
|
}
|