This book is organized into nine chapters, with each one focusing on a different aspect of Windows interoperability. The following sections provide a brief summary of the contents of each chapter.
This chapter discusses the use of Platform Invocation Services (PInvoke) to access C-style functions from managed .NET code. It includes recipes that demonstrate how to declare and use unmanaged functions, change the calling convention and character set, handle errors and exceptions, and manage memory.
This chapter is a logical continuation of Chapter 1 and covers topics that relate to user-defined types such as structures and classes. Recipes in this chapter cover passing structures, classes, and arrays between managed and unmanaged code; controlling the field alignment within a structure; and implementing field-level marshaling within a structure.
This chapter covers the topics associated with using Win32 functions from managed .NET code. Recipes include accessing the ANSI or Unicode version of a function, retrieving Win32 error codes, handling callbacks, and passing handles and objects between managed and unmanaged code. The chapter also provides a recipe that illustrates how to replace a set of Win32 functions entirely with managed code.
The focus of this chapter is on using C++ to solve various interop problems. Recipes in this chapter include how to mix managed and unmanaged code in a project and within a single source file, how to use managed objects from unmanaged code, and how to marshal strings and structures with embedded pointers and callbacks. There is also a recipe that demonstrates the use of C++ as a custom COM wrapper.
All of the recipes in this chapter demonstrate some aspect of using COM components from managed .NET code. Recipes include importing and using a COM object, handling COM events, marshaling common COM data types, handling HRESULTcodes, and providing error information.
The recipes in this chapter are the reciprocal of Chapter 5. They show you how to expose managed .NET code as COM components, suitable for use by any COM client. Recipes include exposing managed components to COM by defining your own interface, controlling COM identity and visibility, exposing managed events to COM, and handling HRESULT codes and managed exceptions.
This chapter continues where Chapter 6 left off, focusing on a set of specific COM marshaling problems. Recipes include how to control parameter direction; how to marshal strings, arrays, Variants, and currency; and how to marshal classes and structures to COM clients.
This chapter shows you how to make use of COM+ services from managed code. Recipes include developing a COM+ component in managed code, installing and registering the component, using just-in-time (JIT) activation, using object pooling, implementing role-based COM+ security, and writing Queued Components.
The recipes in this chapter all focus on the use of COM+ transactions. The recipes demonstrate how to enable transactions, how to place a vote for a transaction, how to use the new .NET Framework 2.0 transactional code blocks, how to build your own resource manager, and how to use services without components.