As you know, in-process components always run within the address space of their caller, except when run in a surrogate. This means that transferring function parameters, whether values or pointers to data, between the client and the component is a relatively trivial matter. When you make cross-process calls to a component running on the local machine or on a remote machine, things get more complicated. In such cases, all the data that needs to be shared by the client and the component must be neatly packaged and transmitted by any means available. This process is called marshaling, which according to the closest available dictionary means to arrange in proper order. We touched on marshaling in earlier chapters, and in this chapter we'll delve into the details of this interesting and rather complex subject.
Any component designed to run outside the context, apartment, process, or local machine of the client process must address the issue of marshaling. When a method call is executed on an object in another address space, COM+ needs to organize the data to be transferred. All of the method's parameters must be packed and transmitted from the caller's address space to the receiver's address space. For primitive data types such as characters and integers, marshaling does not sound all that difficult. But for more complex types such as structures, strings, arrays, linked lists, and interface pointers, marshaling can become exceedingly complex.
The subject of marshaling function parameters, whether integers or linked lists, was thoroughly researched during the development of Remote Procedure Call (RPC) systems.1 Most RPC systems, including Microsoft Windows, transmit method parameters using the Network Data Representation (NDR)2 standard adopted by the Open Software Foundation (OSF). Because COM+ is built on top of Microsoft RPC, it can leverage most of the RPC functionality—except in the area of interface pointers. RPC systems have no concept of interface pointers. In fact, the COM+ marshaling architecture deals almost exclusively with how to pass an interface pointer from the component to the client. In this chapter, we'll show you how to use custom marshaling, the basic marshaling architecture of COM+, to handle the marshaling requirements of the ISum interface.3