Memory Layout of Interfaces

You know that the interface is just a group of functions, but what is it really in terms of memory? Well, to understand interfaces, you have to know how a client binds to functions in a DLL.

Whenever you load a program, the code for the program is mapped into virtual memory. The program uses a CPU register known as the instruction pointer that tells it in essence what line of code to execute next (in reality it stores the memory location of what machine instruction to execute next). Whenever the program encounters a call to a function or a subroutine, the machine code simply tells the instruction pointer to jump to the place in memory where the function resides.

Thus, any time you make a method call, all that you are doing is changing the instruction pointer to point to a different piece of code. This is often referred to as making a “jump.” The address of the next instruction after the jump instruction (the address that would have come next if we had not made the jump, often called the return address) is saved. When the program is done executing the functions, it issues a “return.” The return simply sets the instruction pointer to the return address. (Granted, this is a simplified view, but this is in essence what happens.)

DLLs contain a number of exported functions. Since making method calls is simply jumping to a particular place in memory, this means the client code needs to know where the code for the functions in the DLL resides. However, the code ...

Get COM+ Programming with Visual Basic now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.