PInvoke, Wrapper Classes and the Adapter Pattern in C#
PInvoke (sometimes stylized as P/Invoke) allows managed C# code to talk to native libraries in Windows, MacOS and Linux.
It's usually best to encase PInvoke calls in to native DLLs in their own adapter that is in turn encased in a friendly .NET wrapper. This prevents users from dealing with the intricacies and headaches of PInvoke.
This is a classic use of the Adapter Design Pattern, which allows two non-compatible types to interact with each other.
If you are using MacOS or Linux, you can follow along with this example by downloading Oracle Virtualbox from here: https://www.virtualbox.org/
You can also download Windows 10 for Virtualbox here: https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/
The code for this video is available here: https://github.com/mcbethr/Wrapper-Adapter-And-PInvoke-Video