To fully use P/Invoke services, you need to understand the concepts of marshaling and callbacks. This section explores each of these topics. Pay particular attention to marshaling because COM Interop uses the same underlying marshaling service as P/Invoke. COM Interop is covered in Chapters 8, “Using COM/COM+ in Managed Code,” and 9, “Using Managed Code as a COM/COM+ Component.”
It would not be practical to show examples from every language throughout this chapter, so the focus has been narrowed to C#. The same features that are shown are available in most languages supported in the .NET Framework.
All P/Invoke calls are declared through DllImportAttribute. In its simplest ...