Summary
If your head is spinning, it is because this is difficult stuff. The good news is that VB does almost everything for you automatically.
In this chapter you learned the memory layout of interfaces. The main
thing to remember is the memory layout of an interface is the same in
every language: a memory address known as a vptr points to a vtable.
A vtable is nothing more than an array of pointers to functions. Each
vtable begins with pointers to functions of the
IUnknown interface. In fact, the true definition
of a COM object is an object that implements the
IUnknown interface. IUnknown
enables us to do two main tasks. First, it gives us a mechanism by
which we can accomplish polymorphism (through
QueryInterface). Second, it gives us two methods
(AddRef and Release) by which we can do reference counting.
Some clients are not able to use just any interface directly. For
these clients, Microsoft provides a special interface known as
IDispatch. IDispatch enables a
client to ask the server to execute a method on its behalf using its
name. A client using IDispatch first asks for a
DispID for a certain method using the
GetIDsOfNames function. Then, it calls the
Invoke function to execute the method. VB
automatically adds support for IDispatch to every
COM object. In fact, every interface created in VB is a dual
interface. A dual interface is one that is derived from
IDispatch, instead of directly from
IUnknown.
In the next chapter, you will learn how VB COM objects are packaged. We are ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access