Sometimes you need a low-level function to perform a task. For example, you might need to monitor system messages and act on them by calling a Windows function that the .NET Framework doesn't support. Microsoft continually improves the support that .NET Framework provides for low-level Windows functionality, so the need to perform low-level tasks will decrease over time. However, there is always a need to perform them because Microsoft won't support every low-level Windows function as part of the .NET Framework, and you may need low-level calls to access third-party software or hardware. C# really excels when you need to perform low-level tasks because it supports functionality (such as unsafe pointers) not found in other languages such as Visual Basic.NET. You use the Platform Invoke (P/Invoke) functionality that the .NET Framework provides to perform low-level tasks.
This chapter can't provide you with everything you need to know about working with P/Invoke. In fact, I've written an entire book on the topic, .NET Framework Solutions: In Search of the Lost Win32 API (Sybex, 2002). However, this chapter does provide you with a good overview of the topic that you can use to extend your reach from managed applications into the world of native code.
Applications that contain function calls that rely on P/Invoke aren't platform independent. If you want to use your application on Linux or the Macintosh using Mono (