[comp.windows.ms] Indirect function calls

marco@hpmcaa.HP.COM (Marco Dalla-Gasperina) (03/03/89)

What are the possibilities of using indirect function calls like

   x= (*foo)(14);

in windows?  Does windows itself have a mechanism that we can use
or are they totally out of the question like retaining far pointers
to memory blocks...

I guess I'm interested in far calls.

marco

mguyott@mirror.UUCP (Marc Guyott) (03/04/89)

In article <6970002@hpmcaa.HP.COM> marco@hpmcaa.HP.COM (Marco Dalla-Gasperina) writes:
>What are the possibilities of using indirect function calls like
>
>   x= (*foo)(14);
>
>in windows?  Does windows itself have a mechanism that we can use
>or are they totally out of the question like retaining far pointers
>to memory blocks...
>
>I guess I'm interested in far calls.

As long as you specified the Windows compiler flags and you define the
actual function as "far" you should have no problems with indirect function
calls.  The address that is indicated by the name of a "far" function is
actually the address of a reload thunk in the entry table for your program.
Windows keeps this table in one of two fixed segments that it builds for each
program when the program is initially loaded.  Making an indirect call will
still go to the reload thunk which will load the appropriate code segment if
it is not already in memory (or cause the correct routine to be called even
if the code segment has moved in memory).


For a more detailed explanation I recommend that you look at the section
called "Windows Runs the Program" on pages 300 and 301 of Charles Petzold's
"Programming Windows" book.  I think he does a nice job of explaining what
Windows does when relocating code and data segments.

I hope this helps.                                 Marc
----
              "All my life I always wanted to BE somebody.
               I see now I should have been more specific."
                             Jane Wagner
Marc Guyott                                         mguyott@mirror.TMC.COM
{mit-eddie, pyramid, harvard!wjh12, xait, datacube}!mirror!mguyott
Mirror Systems	Cambridge, MA  02140                617/661-0777

bturner@hpcvlx.HP.COM (Bill Turner) (03/04/89)

> What are the possibilities of using indirect function calls like
> 
>    x= (*foo)(14);
> 
> in windows?  Does windows itself have a mechanism that we can use
> or are they totally out of the question like retaining far pointers
> to memory blocks...

Function pointers work.  If the calling and called procedures are 
in the same segment, there is absolutely no problem.  If they are in
different segments in the same program/library, again no problem (LINK4
produces the correct code thunks, which are loaded into fixed memory).

--Bill Turner