Importing function pointers without a DLL
Posted: Thu Jun 16, 2005 1:40 am
I didnt find any other way to share this but over this forum, so here goes.
this should be builtin in my opinion, for easier use of newlisp.dll
i just stripped down the p_importLib() function and registered it as
{} = optional, win32 only
Works quite nicely. many thanks to the author of newlisp for making it so easy to add stuff. =)
this should be builtin in my opinion, for easier use of newlisp.dll
i just stripped down the p_importLib() function and registered it as
Code: Select all
(importfn functionName functionAddress {callingConvention})
Code: Select all
CELL * p_importFunc(CELL * params)
{
char * funcName;
UINT funcPtr;
#ifdef WINCC
char * options = NULL;
#endif
CELL * pCell;
SYMBOL * symbol;
params = getString(params, &funcName);
params = getInteger(params, &funcPtr);
#ifdef WINCC
if(params != nilCell)
getString(params, &options);
if(options != NULL && strcmp(options, "cdecl") == 0)
pCell = getCell(CELL_IMPORT_CDECL);
else
pCell = getCell(CELL_IMPORT_DLL);
#else
pCell = getCell(CELL_IMPORT_CDECL);
#endif
symbol = translateCreateSymbol(funcName, pCell->type, currentContext, TRUE);
if(isProtected(symbol->flags))
return(errorProcExt2(ERR_SYMBOL_PROTECTED, stuffSymbol(symbol)));
deleteList((CELL *)symbol->contents);
symbol->contents = (UINT)pCell;
pCell->contents = (UINT)funcPtr;
pCell->aux = (UINT)symbol->name;
if(pCell->contents == 0)
return(errorProcExt2(ERR_IMPORT_FUNC_NOT_FOUND, stuffString(funcName)));
return(copyCell(pCell));
}