PInvoke, Wrapper Classes and the Adapter Pattern in C#
Channel: Ryan McBeth
Date: 01/11/2021

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 can be found on:
ryanmcbeth.com
or
https://github.com/mcbethr/Wrapper-Adapter-And-PInvoke-Video

"Romania-1603 - Throne Room" by archer10 (Dennis) is licensed under CC BY-SA 2.0
"Brian Kernighan 1" by red_cornet is licensed under CC BY 2.0
"Dennis Ritchie" by Javier Martínez Ortiz is licensed under CC BY-NC-SA 2.0
"The Chart Room Bar" by Sam Howzit is licensed under CC BY 2.0
"Captain Tony's Saloon" by Sam Howzit is licensed under CC BY 2.0

You'll Be Back
Jonathan Groff, Original Broadway Cast of Hamilton
And Lin-Manuel Miranda