Defining COM Interfaces

There are nearly 200 Microsoft-defined COM interfaces, many of which are implemented in the COM libraries. In most cases you can reuse these generic interfaces. However, some applications have specific requirements that make it desirable, or necessary, to define your own object interfaces.

All COM interfaces must derive, either directly or indirectly, from the IUnknown interface. Within that constraint, your custom interface can support almost any method or parameter, including asynchronous methods. You can also generate a type library for your custom interfaces so clients can access information about your object's methods at run time. Once you define an interface, describe it in Microsoft Interface Definition Language (MIDL), compile and register it, you use it just like any generic interface. With DCOM, interface methods are available both to remote processes and to other processes on the same machine.

This chapter explains how to use MIDL to define COM interfaces and how to build a type library or a proxy/stub DLL to handle the interprocess communication. COM programming experience is assumed. See The Component Object Model for the fundamentals of COM interfaces, and COM Clients and Servers for information on how clients and servers interact.

Because you will be using the same steps and tools that you would use to build a conventional client/server RPC application, you should first work through the short Tutorial in the RPC Programmer's Guide and Reference if you are not already familiar with RPC and MIDL.

Finally, building COM interfaces requires a development environment that includes either Microsoft Windows NT® (version 4.0 or later) or Windows® 95, a 32-bit C/C++ compiler, and the Microsoft Platform Software Development Kit (SDK), which includes the Midl.exe compiler.

The steps in creating a COM interface are: