在调用 win32 库的时候,小伙伴会遇到的问题是不知道对应的 win32 函数应该如何写。或者在网上抄了的代码的实现都有些诡异,想要自己封装发现工作量太大。好消息是官方将 PInvoke 库在 dotnet 基金会完全开源,包含了大量的 Win32 库,如 gdi32.dll 和 kernel32.dll 和 user32.dll 等
使用官方的库的优势是什么呢?第一个就是减少从网上复制粘贴有趣的 PInvoke 调用实现,其次是质量上能保底。虽然官方的实现也不够完美,例如 User32 的 GetWindowLong 方法依然有坑。但是因为此项目是在 github 开源 因此也会有大量的小伙伴入坑不断的修复,相对来说应该会比自己实现的好一些
现在官方已经将大量的 dll 进行了封装
已经实现的 dll 如下
Library | Package name | NuGet | Description |
---|---|---|---|
advapi32.dll | PInvoke.AdvApi32 |
Windows Advanced Services | |
bcrypt.dll | PInvoke.BCrypt |
Windows Cryptography API: Next Generation | |
cabinet.dll | PInvoke.Cabinet |
Cabinet API Functions | |
cfgmgr32.dll | PInvoke.CfgMgr32 |
Device and Driver Installation | |
crypt32.dll | PInvoke.Crypt32 |
Windows Cryptography API | |
DwmApi.dll | PInvoke.DwmApi |