Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 26, 2023. It is now read-only.
/pinvokePublic archive

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.

License

NotificationsYou must be signed in to change notification settings

dotnet/pinvoke

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

⚠ NOTICE:Check out CsWin32: A new, preferred approach for Win32 p/invokes now exists for C# developers.

This repo is no longer maintained.


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

A unique C# project wraps each native library.The C# project may multi-target in order to support many versions of .NET Framework, .NET Core and .NET Standard.

Win32 APIs for all Windows versions are welcome.Special 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.

This project is supported by the.NET Foundation.

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):

usingPInvoke;usingstaticPInvoke.BCrypt;// Supported in C# 6 (VS2015) and later.

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

varerror=BCryptOpenAlgorithm(AlgorithmIdentifiers.BCRYPT_SHA256_ALGORITHM);// C# 6 syntaxvarerror=BCrypt.BCryptOpenAlgorithm(BCrypt.AlgorithmIdentifiers.BCRYPT_SHA256_ALGORITHM);// C# 5 syntax

Sometimes a PInvoke method may have multiple overloads. For example every method that acceptsstruct* parameters has an overload that acceptsIntPtr in its place. In other cases theremay be overloads that acceptstruct* andstruct?. In some of these cases that can lead tocompiler errors if you pass innull because bothstruct* andstruct? overloads can match.To resolve the issue, add a cast to your null:(struct?)null to resolve the ambiguity.

What if I need customuint value not provided inenum?

Cast anyuint to specificenum type and pass as parameter.

Design goals

Provide a slightly higher than lowest level API for P/Invoke signatures.For example, instead ofIntPtr parameters anduint flags, you'll seeSafeHandle-derivedtypes as parameters and flagsenum types. API documentation will be provided via XML doc commentsfor easy reading with Intellisense, along with links to the describing pages on MSDNor elsewhere as applicable.

In some cases we offer several overloads of a given native method to offer native pointer andIntPtr access. We encourage folks to try writing C#unsafe code before usingIntPtr becauseit (ironically) can often be easier to write correct and efficient code using native pointers thanall the casting andMarshal call overhead thatIntPtr requires.Note that when a method's only use of a native pointer is its return type, theIntPtr returningvariant must be given a different method name by CLR overloading rules, so look for the same methodbut with an_IntPtr suffix.

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:

LibraryPackage nameNuGetDescription
advapi32.dllPInvoke.AdvApi32NuGetWindows Advanced Services
bcrypt.dllPInvoke.BCryptNuGetWindows Cryptography API: Next Generation
cabinet.dllPInvoke.CabinetNuGetCabinet API Functions
cfgmgr32.dllPInvoke.CfgMgr32NuGetDevice and Driver Installation
crypt32.dllPInvoke.Crypt32NuGetWindows Cryptography API
DwmApi.dllPInvoke.DwmApiNuGetDesktop Window Manager
fusion.dllPInvoke.FusionNuGet.NET Framework Fusion
gdi32.dllPInvoke.Gdi32NuGetWindows Graphics Device Interface
hid.dllPInvoke.HidNuGetWindows Human Interface Devices
iphlpapi.dllPInvoke.IPHlpApiNuGetIP Helper
kernel32.dllPInvoke.Kernel32NuGetWindows Kernel API
magnification.dllPInvoke.MagnificationNuGetWindows Magnification API
mscoree.dllPInvoke.MSCorEENuGet.NET Framework CLR host
msi.dllPInvoke.MsiNuGetMicrosoft Installer
ncrypt.dllPInvoke.NCryptNuGetWindows Cryptography API: Next Generation
netapi32.dllPInvoke.NetApi32NuGetNetwork Management
newdev.dllPInvoke.NewDevNuGetDevice and Driver Installation
ntdll.dllPInvoke.NTDllNuGetWindows NTDll
psapi.dllPInvoke.PsapiNuGetWindows Process Status API
setupapi.dllPInvoke.SetupApiNuGetWindows setup API
SHCore.dllPInvoke.SHCoreNuGetWindows Shell
shell32.dllPInvoke.Shell32NuGetWindows Shell
user32.dllPInvoke.User32NuGetWindows User Interface
userenv.dllPInvoke.UserenvNuGetWindows User Environment
uxtheme.dllPInvoke.UxThemeNuGetWindows Visual Styles
winusb.dllPInvoke.WinUsbNuGetUSB Driver
WtsApi32.dllPInvoke.WtsApi32NuGetWindows Remote Desktop Services

Check out theP/Invoke coverage we have for each library.

If 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

<addkey="PInvoke"value="https://pkgs.dev.azure.com/andrewarnott/OSS/_packaging/PublicCI/nuget/v3/index.json" />

Contribution

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

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.For more information see the.NET Foundation Code of Conduct.

About

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.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp