interopbook: chapter overview

chapter overview

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.

chapter 1: using c-style APIs

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.

chapter 2: c-style APIs: structures, classes, and arrays

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.

chapter 3: win32 API

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.

chapter 4: using c++ interop

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.

chapter 5: using COM

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.

chapter 6: exposing managed code to COM

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.

chapter 7: marshaling to COM clients

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.

chapter 8: COM+ enterprise services

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.

chapter 9: COM+ enterprise services transactions

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.