🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.windows.ms.programmer
1 messages
1 total messages Started by Ed Ipser Mon, 07 Sep 1992 04:20
BC++/MS Windows: How Do You Call Anonymous Functions?
#466
Author: Ed Ipser
Date: Mon, 07 Sep 1992 04:20
54 lines
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?
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads