Article View: comp.windows.ms.programmer
Article #466BC++/MS Windows: How Do You Call Anonymous Functions?
From: Ed Ipser
Date: Mon, 07 Sep 1992 04:20
Date: Mon, 07 Sep 1992 04:20
54 lines
2069 bytes
2069 bytes
How Do You Call Anonymous Functions?
Here is the problem: I want to write an interpreter under Borland C++
and MS Windows and I need to be able to call arbitrary functions from
within the interpreter such as Windows API functions as well as
user-defined functions from DLLs. Of course, normal function pointers
will not work for two reasons: first, they would require a function
type for every type of function and, worse, the types of functions are
not known when the interpreter is compiled since the user can define
his own.
I know a solution exists because many applications have this capability.
Let me phrase the problem more precisely:
I want to write two functions:
function_type* get_function (
char* dll_file, char* name) ;
the get_function function would return a far pointer to a function from the
name of the DLL containing the function and the name of the function.
and:
void apply_function (
function_type* function,
int parameter_size, void* parameters,
int result_size, void* result) ;
which would push the parameters and result on the stack, call the function, and then
copy the result into the result parameter.
for example, the following would call the Windows max function:
void dummy ()
{
struct
{
int x ;
int y ;
} xy ;
int max ;
apply_function(get_function("windows","max"),4,&xy,2,&max) ;
cout << max ;
} ;
The next question, of course, is how do you do this with data members and
member functions of classes? How do you find the virtual tables?
Technical Details
Message-ID:
<1992Sep7.042033.4884@nuscc.nus.sg>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!darwin.sura.net!jvnc.net!nuscc!solomon.technet.sg!ipserShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!darwin.sura.net!jvnc.net!nuscc!solomon.technet.sg!ipser From: ipser@solomon.technet.sg (Ed Ipser) Newsgroups: comp.windows.ms.programmer,comp.lang.c++ Subject: BC++/MS Windows: How Do You Call Anonymous Functions? Summary: How Do You Call Anonymous Functions? Message-ID: <1992Sep7.042033.4884@nuscc.nus.sg> Date: 7 Sep 92 04:20:33 GMT Sender: usenet@nuscc.nus.sg Organization: TECHNET, Singapore Lines: 54