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.
Перейти к файлу
Andrew Arnott 2a7c2a4408 Fix line endings 2016-09-04 12:56:07 -07:00
src Fix line endings 2016-09-04 12:56:07 -07:00
templates Fixes typo on CONTRIBUTING.md and AddNewCoreLibrary.md 2016-08-11 21:38:35 +02:00
tools Quieter output when updating coverage map 2016-08-14 23:20:16 -07:00
.gitattributes Fix line endings 2016-09-04 12:56:07 -07:00
.gitignore Merge branch 'develop' into feature/display-api 2016-08-14 18:45:42 +02:00
CONTRIBUTING.md Address pinvoke.net question in contrib doc 2016-08-14 10:38:18 -07:00
COPYRIGHT.md Add me (vbfox) to the COPYRIGHT.md 2015-10-26 22:16:47 +01:00
LICENSE.txt Change copyright notice from license file 2015-11-09 13:36:31 -08:00
README.md Adding SHCore project 2016-08-03 22:36:44 +02:00
appveyor.yml Add appveyor block option 2016-08-14 23:15:50 -07:00
build.cmd Add restore, build, test script 2016-02-28 17:32:43 -08:00
build.ps1 Fix warning/error counter 2016-05-19 19:25:20 -07:00
coverage.md Update coverage map 2016-08-14 23:23:32 -07:00

README.md

P/Invoke

Build status Join the chat at https://gitter.im/AArnott/pinvoke

Issue Stats Issue Stats

A collection of libraries intended to contain all P/Invoke method signatures for popular operating systems. Think of it as http://pinvoke.net, but proven to compile and work properly, and often with sample usage in the form of unit tests.

Each library is exposed as its own NuGet package, and may include .NET Portable libraries as applicable, exposing those APIs that are available only on Desktop, or Store, or both as appropriate.

Usage

Install the NuGet package(s) for the DLLs you want to P/Invoke into. For example, if you want to P/Invoke into Win32's BCrypt.dll, install this package:

Install-Package PInvoke.BCrypt

Then import the following namespaces, as demonstrated below (if using C# 6):

using PInvoke;
using static PInvoke.BCrypt; // Supported in C# 6 (VS2015) and later.

This will allow you to conveniently call these methods directly by method name:

var error = BCryptOpenAlgorithm(AlgorithmIdentifiers.BCRYPT_SHA256_ALGORITHM); // C# 6 syntax
var error = BCrypt.BCryptOpenAlgorithm(BCrypt.AlgorithmIdentifiers.BCRYPT_SHA256_ALGORITHM); // C# 5 syntax

Sometimes a PInvoke method may have multiple overloads. For example every method that accepts struct* parameters has an overload that accepts IntPtr in its place. In other cases there may be overloads that accept struct* and struct?. In some of these cases that can lead to compiler errors if you pass in null because both struct* and struct? overloads can match. To resolve the issue, add a cast to your null: (struct?)null to resolve the ambiguity.

Design goals

Provide a slightly higher than lowest level API for P/Invoke signatures. For example, instead of IntPtr parameters and uint flags, you'll see SafeHandle-derived types as parameters and flags enum types. API documentation will be provided via XML doc comments for easy reading with Intellisense, along with links to the describing pages on MSDN or elsewhere as applicable.

Distribution

This library should be available on NuGet for easy consumption by your projects. You may also copy and paste the P/Invoke signatures you need directly into your projects if desired.

Packages:

Library Package name NuGet Description
advapi32.dll PInvoke.AdvApi32 NuGet Windows Advanced Services
bcrypt.dll PInvoke.BCrypt NuGet Windows Cryptography API: Next Generation
crypt32.dll PInvoke.Crypt32 NuGet Windows Cryptography API
DwmApi.dll PInvoke.DwmApi NuGet Desktop Window Manager
gdi32.dll PInvoke.Gdi32 NuGet Windows Graphics Device Interface
hid.dll PInvoke.Hid NuGet Windows Human Interface Devices
kernel32.dll PInvoke.Kernel32 NuGet Windows Kernel API
mscoree.dll PInvoke.MSCorEE NuGet .NET Framework CLR host
msi.dll PInvoke.Msi NuGet Microsoft Installer
fusion.dll PInvoke.Fusion NuGet .NET Framework Fusion
ncrypt.dll PInvoke.NCrypt NuGet Windows Cryptography API: Next Generation
netapi32.dll PInvoke.NetApi32 NuGet Network Management
ntdll.dll PInvoke.NTDll NuGet Windows NTDll
psapi.dll PInvoke.Psapi NuGet Windows Process Status API
setupapi.dll PInvoke.SetupApi NuGet Windows setup API
shell32.dll PInvoke.Shell32 NuGet Windows Shell
SHCore.dll PInvoke.SHCore NuGet Windows Shell
user32.dll PInvoke.User32 NuGet Windows User Interface
userenv.dll PInvoke.Userenv NuGet Windows User Environment
uxtheme.dll PInvoke.UxTheme NuGet Windows Visual Styles

Check out the P/Invoke coverage we have for each library.

Contribution

Please consider contributing more P/Invoke method signatures to this project. Once you contribute, you can immediately consume your additions without waiting for another public release of the library.