{"id":13595248,"url":"https://github.com/dotnet/pinvoke","last_synced_at":"2025-09-30T18:31:51.301Z","repository":{"id":40320712,"uuid":"44758360","full_name":"dotnet/pinvoke","owner":"dotnet","description":"A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.","archived":true,"fork":false,"pushed_at":"2023-07-26T11:36:20.000Z","size":5709,"stargazers_count":2089,"open_issues_count":1,"forks_count":219,"subscribers_count":78,"default_branch":"main","last_synced_at":"2024-05-02T00:10:00.432Z","etag":null,"topics":["dotnet","interop","pinvoke"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dotnet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"aarnott","custom":"https://keybase.io/aarnott"}},"created_at":"2015-10-22T16:28:01.000Z","updated_at":"2024-04-29T01:23:46.000Z","dependencies_parsed_at":"2023-02-17T05:05:30.189Z","dependency_job_id":"39645928-0a63-48f5-9d47-e6c7c73c5685","html_url":"https://github.com/dotnet/pinvoke","commit_stats":{"total_commits":1671,"total_committers":58,"mean_commits":"28.810344827586206","dds":0.5487731897067625,"last_synced_commit":"93de9b78bcd8ed84d02901b0556c348fa66257ed"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet%2Fpinvoke","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet%2Fpinvoke/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet%2Fpinvoke/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet%2Fpinvoke/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotnet","download_url":"https://codeload.github.com/dotnet/pinvoke/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234705916,"owners_count":18874428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","interop","pinvoke"],"created_at":"2024-08-01T16:01:46.347Z","updated_at":"2025-09-30T18:31:50.585Z","avatar_url":"https://github.com/dotnet.png","language":"C#","readme":"# P/Invoke\n\n**⚠ NOTICE: [Check out CsWin32](https://github.com/dotnet/pinvoke/issues/565): A new, preferred approach for Win32 p/invokes now exists for C# developers.**\n\nThis repo is no longer maintained.\n\n---\n\nA collection of libraries intended to contain all P/Invoke method signatures for popular operating systems.\nThink of it as https://pinvoke.net, but proven to compile and work properly, and often\nwith sample usage in the form of unit tests.\n\nA unique C# project wraps each native library.\nThe C# project may multi-target in order to support many versions of .NET Framework, .NET Core and .NET Standard.\n\nWin32 APIs for all Windows versions are welcome.\nSpecial Windows Store targeted assemblies omit p/invoke signatures to banned APIs so your Store apps can depend on these libraries without getting rejected by the Store certification process.\n\nThis project is supported by the [.NET Foundation](https://dotnetfoundation.org).\n\n## Usage\n\nInstall the NuGet package(s) for the DLLs you want to P/Invoke into.\nFor example, if you want to P/Invoke into Win32's BCrypt.dll, install this package:\n\n```powershell\nInstall-Package PInvoke.BCrypt\n```\n\nThen import the following namespaces, as demonstrated below (if using C# 6):\n\n```csharp\nusing PInvoke;\nusing static PInvoke.BCrypt; // Supported in C# 6 (VS2015) and later.\n```\n\nThis will allow you to conveniently call these methods directly by method name:\n\n```csharp\nvar error = BCryptOpenAlgorithm(AlgorithmIdentifiers.BCRYPT_SHA256_ALGORITHM); // C# 6 syntax\nvar error = BCrypt.BCryptOpenAlgorithm(BCrypt.AlgorithmIdentifiers.BCRYPT_SHA256_ALGORITHM); // C# 5 syntax\n```\n\nSometimes a PInvoke method may have multiple overloads. For example every method that accepts\n`struct*` parameters has an overload that accepts `IntPtr` in its place. In other cases there\nmay be overloads that accept `struct*` and `struct?`. In some of these cases that can lead to\ncompiler errors if you pass in `null` because both `struct*` and `struct?` overloads can match.\nTo resolve the issue, add a cast to your null: `(struct?)null` to resolve the ambiguity.\n\n### What if I need custom `uint` value not provided in `enum`?\n\nCast any `uint` to specific `enum` type and pass as parameter.\n\n## Design goals\n\nProvide a slightly higher than lowest level API for P/Invoke signatures.\nFor example, instead of `IntPtr` parameters and `uint` flags, you'll see `SafeHandle`-derived\ntypes as parameters and flags `enum` types. API documentation will be provided via XML doc comments\nfor easy reading with Intellisense, along with links to the describing pages on MSDN\nor elsewhere as applicable.\n\nIn some cases we offer several overloads of a given native method to offer native pointer and\n`IntPtr` access. We encourage folks to try writing C# `unsafe` code before using `IntPtr` because\nit (ironically) can often be easier to write correct and efficient code using native pointers than\nall the casting and `Marshal` call overhead that `IntPtr` requires.\nNote that when a method's only use of a native pointer is its return type, the `IntPtr` returning\nvariant must be given a different method name by CLR overloading rules, so look for the same method\nbut with an `_IntPtr` suffix.\n\n## Distribution\n\nThis library should be available on NuGet for easy consumption by your projects.\nYou may also copy and paste the P/Invoke signatures you need directly into your projects if desired.\n\nPackages:\n\nLibrary      | Package name     | NuGet       | Description\n-------------|------------------|-------------|-------------\nadvapi32.dll |`PInvoke.AdvApi32`| [![NuGet](https://buildstats.info/nuget/PInvoke.AdvApi32)](https://www.nuget.org/packages/PInvoke.AdvApi32)|Windows Advanced Services\nbcrypt.dll   |`PInvoke.BCrypt`  | [![NuGet](https://buildstats.info/nuget/PInvoke.BCrypt)](https://www.nuget.org/packages/PInvoke.BCrypt)|[Windows Cryptography API: Next Generation][CNG]\ncabinet.dll  |`PInvoke.Cabinet` | [![NuGet](https://buildstats.info/nuget/PInvoke.Cabinet)](https://www.nuget.org/packages/PInvoke.Cabinet)|[Cabinet API Functions][Cabinet]\ncfgmgr32.dll |`PInvoke.CfgMgr32`| [![NuGet](https://buildstats.info/nuget/PInvoke.CfgMgr32)](https://www.nuget.org/packages/PInvoke.CfgMgr32)|[Device and Driver Installation][CfgMgr32]\ncrypt32.dll  |`PInvoke.Crypt32` | [![NuGet](https://buildstats.info/nuget/PInvoke.Crypt32)](https://www.nuget.org/packages/PInvoke.Crypt32)|[Windows Cryptography API][Crypt32]\nDwmApi.dll   |`PInvoke.DwmApi`  | [![NuGet](https://buildstats.info/nuget/PInvoke.DwmApi)](https://www.nuget.org/packages/PInvoke.DwmApi)|[Desktop Window Manager][DwmApi]\nfusion.dll   |`PInvoke.Fusion`  | [![NuGet](https://buildstats.info/nuget/PInvoke.Fusion)](https://www.nuget.org/packages/PInvoke.Fusion)|.NET Framework Fusion\ngdi32.dll    |`PInvoke.Gdi32`   | [![NuGet](https://buildstats.info/nuget/PInvoke.Gdi32)](https://www.nuget.org/packages/PInvoke.Gdi32)|[Windows Graphics Device Interface][Gdi]\nhid.dll      |`PInvoke.Hid`     | [![NuGet](https://buildstats.info/nuget/PInvoke.Hid)](https://www.nuget.org/packages/PInvoke.Hid)|[Windows Human Interface Devices][Hid]\niphlpapi.dll |`PInvoke.IPHlpApi`| [![NuGet](https://buildstats.info/nuget/PInvoke.IPHlpApi)](https://www.nuget.org/packages/PInvoke.IPHlpApi)|[IP Helper](IPHlpApi)\nkernel32.dll |`PInvoke.Kernel32`| [![NuGet](https://buildstats.info/nuget/PInvoke.Kernel32)](https://www.nuget.org/packages/PInvoke.Kernel32)|Windows Kernel API\nmagnification.dll |`PInvoke.Magnification`| [![NuGet](https://buildstats.info/nuget/PInvoke.Magnification)](https://www.nuget.org/packages/PInvoke.Magnification)|[Windows Magnification API][Magnification]\nmscoree.dll  |`PInvoke.MSCorEE` | [![NuGet](https://buildstats.info/nuget/PInvoke.MSCorEE)](https://www.nuget.org/packages/PInvoke.MSCorEE)|.NET Framework CLR host\nmsi.dll      |`PInvoke.Msi`     | [![NuGet](https://buildstats.info/nuget/PInvoke.Msi)](https://www.nuget.org/packages/PInvoke.Msi)|[Microsoft Installer][Msi]\nncrypt.dll   |`PInvoke.NCrypt`  | [![NuGet](https://buildstats.info/nuget/PInvoke.NCrypt)](https://www.nuget.org/packages/PInvoke.NCrypt)|[Windows Cryptography API: Next Generation][CNG]\nnetapi32.dll |`PInvoke.NetApi32`| [![NuGet](https://buildstats.info/nuget/PInvoke.NetApi32)](https://www.nuget.org/packages/PInvoke.NetApi32)|[Network Management][NetApi32]\nnewdev.dll   |`PInvoke.NewDev`  | [![NuGet](https://buildstats.info/nuget/PInvoke.NewDev)](https://www.nuget.org/packages/PInvoke.NewDev)|[Device and Driver Installation][NewDev]\nntdll.dll    |`PInvoke.NTDll`   | [![NuGet](https://buildstats.info/nuget/PInvoke.NTDll)](https://www.nuget.org/packages/PInvoke.NTDll)|Windows NTDll\npsapi.dll    |`PInvoke.Psapi`   | [![NuGet](https://buildstats.info/nuget/PInvoke.Psapi)](https://www.nuget.org/packages/PInvoke.Psapi)|[Windows Process Status API][Psapi]\nsetupapi.dll |`PInvoke.SetupApi`| [![NuGet](https://buildstats.info/nuget/PInvoke.SetupApi)](https://www.nuget.org/packages/PInvoke.SetupApi)|[Windows setup API][SetupApi]\nSHCore.dll   |`PInvoke.SHCore`  | [![NuGet](https://buildstats.info/nuget/PInvoke.SHCore)](https://www.nuget.org/packages/PInvoke.SHCore)|[Windows Shell][Shell32]\nshell32.dll  |`PInvoke.Shell32` | [![NuGet](https://buildstats.info/nuget/PInvoke.Shell32)](https://www.nuget.org/packages/PInvoke.Shell32)|[Windows Shell][Shell32]\nuser32.dll   |`PInvoke.User32`  | [![NuGet](https://buildstats.info/nuget/PInvoke.User32)](https://www.nuget.org/packages/PInvoke.User32)|[Windows User Interface][User32]\nuserenv.dll  |`PInvoke.Userenv` | [![NuGet](https://buildstats.info/nuget/PInvoke.Userenv)](https://www.nuget.org/packages/PInvoke.Userenv)|Windows User Environment\nuxtheme.dll  |`PInvoke.UxTheme` | [![NuGet](https://buildstats.info/nuget/PInvoke.UxTheme)](https://www.nuget.org/packages/PInvoke.UxTheme)|[Windows Visual Styles][UxTheme]\nwinusb.dll   |`PInvoke.WinUsb`  | [![NuGet](https://buildstats.info/nuget/PInvoke.WinUsb)](https://www.nuget.org/packages/PInvoke.WinUsb)|[USB Driver][WinUsb]\nWtsApi32.dll |`PInvoke.WtsApi32`| [![NuGet](https://buildstats.info/nuget/PInvoke.WtsApi32)](https://www.nuget.org/packages/PInvoke.WtsApi32)|[Windows Remote Desktop Services][WtsApi32]\n\nCheck out the [P/Invoke coverage][PInvokeCoverageReport] we have for each library.\n\nIf you need a P/Invoke that is in our source code but not yet released to nuget.org, you can consume the packages directly from our CI feed by adding this package source to your nuget.config file\n\n```xml\n\u003cadd key=\"PInvoke\" value=\"https://pkgs.dev.azure.com/andrewarnott/OSS/_packaging/PublicCI/nuget/v3/index.json\" /\u003e\n```\n\n## Contribution\n\nPlease consider [contributing](CONTRIBUTING.md) more P/Invoke method signatures to this project.\nOnce you contribute, you can immediately consume your additions without waiting for another\npublic release of the library.\n\nThis project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.\nFor more information see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).\n\n[CfgMgr32]: https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/\n[CNG]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa376210\n[Crypt32]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa380256\n[DwmApi]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa969540.aspx\n[Hid]: https://msdn.microsoft.com/en-us/library/windows/hardware/ff538865\n[IPHlpApi]: https://docs.microsoft.com/en-us/windows/win32/api/_iphlp/\n[Magnification]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms692162\n[Msi]: https://msdn.microsoft.com/en-us/library/aa372860.aspx\n[SetupApi]: https://msdn.microsoft.com/en-us/library/windows/hardware/ff550855\n[Gdi]: https://msdn.microsoft.com/en-us/library/dd145203\n[Psapi]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684884.aspx\n[UxTheme]: https://msdn.microsoft.com/en-us/library/windows/desktop/bb773187.aspx\n[NetApi32]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa370680.aspx\n[NewDev]: https://docs.microsoft.com/en-us/windows/win32/api/newdev/\n[Shell32]: https://msdn.microsoft.com/en-us/library/windows/desktop/bb773177.aspx\n[WinUsb]: https://docs.microsoft.com/en-us/windows/win32/api/winusb/\n[WtsApi32]: https://msdn.microsoft.com/en-us/library/aa383468(v=vs.85).aspx\n[Cabinet]: https://docs.microsoft.com/en-us/windows/win32/devnotes/cabinet-api-functions\n[User32]: https://docs.microsoft.com/en-us/windows/win32/api/winuser\n\n[PInvokeCoverageReport]: https://github.com/dotnet/pinvoke/wiki/coverage\n","funding_links":["https://github.com/sponsors/aarnott","https://keybase.io/aarnott"],"categories":["C#","Uncategorized","C\\#","Interoperability","互操作"],"sub_categories":["Uncategorized","GUI - other"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotnet%2Fpinvoke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotnet%2Fpinvoke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotnet%2Fpinvoke/lists"}