Details of Platform Invoke

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.”

Note

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.

Declaring the Function: DllImport Attribute

All P/Invoke calls are declared through DllImportAttribute. In its simplest ...

Get .NET Common Language Runtime Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.