PInvoke
Platform Invocation Services (PInvoke) is a .NET runtime feature that enables managed code to call functions exported by unmanaged libraries, such as native Windows API DLLs or cross‑platform shared libraries. It is used to reuse native code or access operating system facilities from managed code.
PInvoke declares a managed method as external and annotates it with DllImport, specifying the library name
Example: static class NativeMethods { [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern int MessageBox(IntPtr hWnd, string
Platform differences affect behavior. Windows typically uses .dll libraries; Linux uses .so and macOS uses .dylib.
Limitations and best practices include minimizing marshaling in hot paths, preferring simple data types, and using