Microsoft has a very nice Windows API wrapper included in .NET framework. It is stored in Microsoft.Win32.UnsafeNativeMethods , Microsoft.Win32.SafeNativeMethods and Microsoft.Win32.NativeMethods.Unfortunately they aren't accessible because they are declared as private. Is there a way of accessing them easily?
Most method definitions in those classes (if not all) are extern
declarations with DllImport attributes that refer to functions in the Windows API through P/Invoke. In doesn't matter where these declarations reside. You can create your own class named UnsafeNativeMethods or SafeNativeMethods and put declarations referring to the same Windows API functions in there. You'll find the signatures of many Windows API functions for C# on pinvoke.net.
For what it's worth I always thought there should have been a kernel32.interop.dll etc with the static methods already DllImport'ed. But I've resorted to creating my own on an as-needed basis. Over the years I've found I rarely use more than a handful of them but it's such a pain in the ass when I need an API that I haven't imported yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With