Well if I understand what you're saying correctly, you can create a
symbol table at runtime that associates function signatures
(as strings), with function pointers. So for example you could have a
function
void call_func(const char *func_name);
that would search the table, find the apropriate function pointer and
call the function through that.
Well, the thing is I do not have a function pointer at compile time. I
need to generate this function pointer at runtime. I agree that in
case I would have a functionPointer at runtime, I could do what you
say. Let me give you an example.
My "User" species a plugin the following way (in his XML - see very
first note)
<plugin name=myPlugin/>
<function>
<name>myFunc</name>
<returnType>void</returnType>
<signature> () </signature>
</function>
so what I know at runtime is: I have a Library (so/dll) that is called
myPlugin, and there is a function in this plugin that looks like this:
void myFunc()
So, at runtime, here's what I do (giving win-specific code as an
example - you could replace LoadLibraray by dlopen and getProcAddress
by dlsym on UNIX systems ):
HINSTANCE libInstance = LoadLibrary("myPlugin");
if (HINSTANCE){
typedef void (*MYPROC)(); //[1]
MYPROC ProcAddr;
ProcAddr = (MYPROC) getProcAdress (libInstance, "myFunc");
if (NULL != ProcAddr){
(ProcAddr)();
}
}
This code is working! But the thing is: I made the typedef in [1] -
the functionPointer declaration - for this signature at compile time -
and this is *not* what I want. I want to do this at runtime -
constructing it from whatever I get in the XML description of the DLL.
I can't see how to do this besides creating a huge table containing
all possilble signatures that a user might ever come up with - and
than picking the correct sfunctionPointer for this signature out of
this table
))
Since this isn't really feasible, maybe someone comes up with a better
idea how to create that functionPointer at runtime ?