Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.

License

NotificationsYou must be signed in to change notification settings

dahall/Vanara

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vanara

VersionDownloadsBuild status

This project contains various .NET assemblies that contain P/Invoke functions, interfaces, enums and structures from Windows libraries. Each assembly is associated with one or a few tightly related libraries. For example, Shlwapi.dll has all the exported functions from shlwapi.lib; Kernel32.dll has all for both kernel32.lib and kernelbase.lib.

All assemblies are available via NuGet and provide builds against .NET 4.5, 4.8, 5.0, 6.0, 7.0, 8.0, .NET Standard 2.0, Core 3.1 and supportSourceLink. Extensions are available for WinForms, WPF, and UWP projects. If you need support for other .NET versions, look to versions 3.3.15 and earlier.

This project releases new versions every few weeks after sufficient testing. New releases are cataloged, along with release notes, in theReleases section and all NuGet packages are published tonuget.org. Each GitHub commit triggers a GitHub Actions build. The status of that build is in the header of this page. The NuGet packages from those pre-release builds are available for test purposes on MyGet's project NuGet source athttps://www.myget.org/feed/Packages/vanara. There are details at that site for adding it as a NuGet Source.

Use

  1. Look for the function you need in Microsoft documentation. Note which library or DLL the function is in.
  2. Confirm the Vanara library exists and has your function by looking at the Supported Libraries table below. Clicking on the Assembly link will take you to a drill down of that assembly's coverage. Find your function and if there is a matching implementation it will appear to the right. You can also use GitHub's project search (upper left of page) to search for your function, method or constant. Make sure to select "In this repository".
  3. Add the assembly to your project via NuGet.
  4. To use the function, you can:
    1. Call it directlyvar bret = Vanara.PInvoke.Kernel32.GetComputerName(sb, ref sbSz);
    2. Under C# 6.0 and later, use a static using directive and call it:
    using static Vanara.PInvoke.Kernel32;var bret = GetComputerName(sb, ref sbSz);
  5. In some cases there is a corresponding helper/wrapper class in one of theSupporting Assemblies, especially for Security, System Services, Forms and Shell. Go to their library page (click on link in section) and look through the classes included in each library.

Design Concepts

  • All functions that are imported from a single DLL should be placed into a single assembly that is named after the DLL.
    • (e.g. The assemblyVanara.PInvoke.Gdi32.dll hosts all functions and supporting enumerations, constants and structures that are exported fromgdi32.dll in the system directory.)
  • Any structure or macro or enumeration (no function) that is used by many libraries is put into eitherVanara.Core orVanara.PInvoke.Shared.
    • (e.g. The macroHIWORD and the structureSIZE are both inVanara.PInvoke.Shared and classes to simplify interop calls and native memory management are inVanara.Core.)
  • Inside a project, all constructs are contained in a file named after the header file (*.h) in which they are defined in the Windows API.
    • (e.g. In theVanara.PInvoke.Kernel32 project directory, you'll find a FileApi.cs, a WinBase.cs and a WinNT.cs file representing fileapi.h, winbase.h and winnt.h respectively.)
  • Where the direct interpretation of a structure or function leads to memory leaks or misuse, I have tried to simplify its use.
  • Where a structure is always passed by reference and where that structure needs to clean up memory allocations, I have changed the structure to a class implementingIDisposable.
  • Wherever possible, all handles have been turned intoSafeHandle derivatives named after the Windows API handle. If those handles require a call to a function to release/close/destroy, a derivedSafeHANDLE exists that performs that function on disposal.
    • e.g.HTOKEN is defined.SafeHTOKEN builds upon that handle with an automated release callingCloseHandle.
  • Wherever possible, all functions that allocate memory that is to be freed by the caller use a safe memory handle.
  • All PInvoke calls are in assemblies prefixed byVanara.PInvoke.
  • If a structure is to passed into a function as a constant, that structure is marshaled using thein statement which will pass the structure by reference without requiring theref keyword.
    • Windows API:BOOL MapDialogRect(HWND hDlg, LPRECT lpRect)
    • Vanara:bool MapDialogRect(HWND hDlg, in RECT lpRect);
  • If there are classes or extensions that make use of the PInvoke calls, they are in wrapper assemblies prefixed byVanara and then followed by a logical name for the functionality. Today, those are Core, Security, SystemServices, Windows.Forms and Windows.Shell.

Supported Libraries

Library/DLLAssemblyCoverageNuGet Link       
aclui.dllVanara.PInvoke.AclUICoverageNugetNuget
activeds.dllVanara.PInvoke.ActiveDSCoverageNugetNuget
advapi32.dll, secur32.dll, authz.dll, sspicli.dll, schannel.dll, tdh.dllVanara.PInvoke.SecurityCoverageNugetNuget
amsi.dllVanara.PInvoke.AMSICoverageNugetNuget
avicap32.dll, avifil32.dll, msacm32.dll, msvfw32.dll, winmm.dllVanara.PInvoke.MultimediaCoverageNugetNuget
avrt.dllVanara.PInvoke.AvrtCoverageNugetNuget
cabinet.dllVanara.PInvoke.CabinetCoverageNugetNuget
CfgMgr32.dllVanara.PInvoke.CfgMgr32CoverageNugetNuget
cimfs.dllVanara.PInvoke.CimFsCoverageNugetNuget
CldApi.dllVanara.PInvoke.CldApiCoverageNugetNuget
clfsw32.dllVanara.PInvoke.ClfsW32CoverageNugetNuget
comctl32.dllVanara.PInvoke.ComCtl32CoverageNugetNuget
ComDlg32.dllVanara.PInvoke.ComDlg32CoverageNugetNuget
credui.dllVanara.PInvoke.CredUICoverageNugetNuget
crypt32.dll, bcrypt.dll, ncrypt.dll, tokenbinding.dll, cryptui.dll, cryptnet.dll, cryptdlg.dllVanara.PInvoke.CryptographyCoverageNugetNuget
d2d1.dllVanara.PInvoke.Direct2DCoverageNugetNuget
d3d11.dll, d3dcsx.dll, d3d11sdklayers.dllVanara.PInvoke.Direct3D11CoverageNugetNuget
d3d12.dllVanara.PInvoke.Direct3D12CoverageNugetNuget
d3dcompiler_47.dll, dxilconv.dllVanara.PInvoke.D3DCompilerCoverageNugetNuget
davclnt.dllVanara.PInvoke.DavClntCoverageNugetNuget
DbgHelp.dll, ImageHlp.dllVanara.PInvoke.DbgHelpCoverageNugetNuget
Dhcpcsvc6.dll, Dhcpcsvc.dllVanara.PInvoke.DhcpCoverageNugetNuget
DnsApi.dllVanara.PInvoke.DnsApiCoverageNugetNuget
dosvc.dllVanara.PInvoke.DOSvcCoverageNugetNuget
drt.dll, drtprov.dll, drttransport.dllVanara.PInvoke.DrtCoverageNugetNuget
dstorage.dllVanara.PInvoke.DStorageCoverageNugetNuget
dwmapi.dllVanara.PInvoke.DwmApiCoverageNugetNuget
dwrite.dllVanara.PInvoke.DWriteCoverageNugetNuget
dxcore.dllVanara.PInvoke.DXCoreCoverageNugetNuget
dxgi.dllVanara.PInvoke.DXGICoverageNugetNuget
ehstorapi.dllVanara.PInvoke.EnhancedStorageCoverageNugetNuget
elscore.dllVanara.PInvoke.ElsCoreCoverageNugetNuget
fhsvcctl.dllVanara.PInvoke.FhSvcCtlCoverageNugetNuget
FirewallApi.dllVanara.PInvoke.FirewallApiCoverageNugetNuget
fundisc.dllVanara.PInvoke.FunDiscCoverageNugetNuget
fwpuclnt.dllVanara.PInvoke.FwpUClntCoverageNugetNuget
gdi32.dllVanara.PInvoke.Gdi32CoverageNugetNuget
httpapi.dllVanara.PInvoke.HttpApiCoverageNugetNuget
imapi2.dll, imapi2fs.dllVanara.PInvoke.IMAPICoverageNugetNuget
imm32.dllVanara.PInvoke.Imm32CoverageNugetNuget
iphlpapi.dllVanara.PInvoke.IpHlpApiCoverageNugetNuget
IScsiDsc.dllVanara.PInvoke.IScsiDscCoverageNugetNuget
kernel32.dll, kernelbase.dll, normaliz.dll, vertdll.dllVanara.PInvoke.Kernel32CoverageNugetNuget
ktmw32.dllVanara.PInvoke.KtmW32CoverageNugetNuget
Lz32.dllVanara.PInvoke.Lz32CoverageNugetNuget
magnification.dllVanara.PInvoke.MagnificationCoverageNugetNuget
mmdevapi.dllVanara.PInvoke.CoreAudioCoverageNugetNuget
mpr.dllVanara.PInvoke.MprCoverageNugetNuget
msctf.dll, input.dll, msimtf.dllVanara.PInvoke.TextServicesFrameworkCoverageNugetNuget
msftedit.dll,riched20.dllVanara.PInvoke.MsftEditCoverageNugetNuget
Msi.dllVanara.PInvoke.MsiCoverageNugetNuget
msrdc.dllVanara.PInvoke.MsRdcCoverageNugetNuget
ndfapi.dllVanara.PInvoke.NdfApiCoverageNugetNuget
netapi32.dllVanara.PInvoke.NetApi32CoverageNugetNuget
netprofm.dllVanara.PInvoke.NetListMgrCoverageNugetNuget
NewDev.dllVanara.PInvoke.NewDevCoverageNugetNuget
ntdll.dllVanara.PInvoke.NtDllCoverageNugetNuget
ntdsapi.dllVanara.PInvoke.NTDSApiCoverageNugetNuget
odbc32.dllVanara.PInvoke.Odbc32CoverageNugetNuget
ole32.dll, oleaut32.dll, propsys.dllVanara.PInvoke.OleCoverageNugetNuget
oleacc.dllVanara.PInvoke.AccessibilityCoverageNugetNuget
oledb.dllVanara.PInvoke.OleDbCoverageNugetNuget
OleDlg.dllVanara.PInvoke.OleDlgCoverageNugetNuget
opcservices.dllVanara.PInvoke.OpcCoverageNugetNuget
P2P.dllVanara.PInvoke.P2PCoverageNugetNuget
pdh.dllVanara.PInvoke.PdhCoverageNugetNuget
PeerDist.dllVanara.PInvoke.PeerDistCoverageNugetNuget
photoacq.dllVanara.PInvoke.PhotoAcquireCoverageNugetNuget
portabledeviceapi.dll, portabledeviceconnectapi.dll, portabledevicetypes.dllVanara.PInvoke.PortableDeviceApiCoverageNugetNuget
powrprof.dllVanara.PInvoke.PowrProfCoverageNugetNuget
ProjectedFSLib.dllVanara.PInvoke.ProjectedFSLibCoverageNugetNuget
qmgr.dllVanara.PInvoke.BITSCoverageNugetNuget
qwave.dll, traffic.dllVanara.PInvoke.QoSCoverageNugetNuget
rpcrt4.dllVanara.PInvoke.RpcCoverageNugetNuget
RstrtMgr.dllVanara.PInvoke.RstrtMgrCoverageNugetNuget
SearchApiVanara.PInvoke.SearchApiCoverageNugetNuget
sensorsapi.dllVanara.PInvoke.SensorsApiCoverageNugetNuget
SetupAPI.dllVanara.PInvoke.SetupAPICoverageNugetNuget
SHCore.dllVanara.PInvoke.SHCoreCoverageNugetNuget
shell32.dll, url.dllVanara.PInvoke.Shell32CoverageNugetNuget
shlwapi.dllVanara.PInvoke.ShlwApiCoverageNugetNuget
taskschd.dll, mstask.dllVanara.PInvoke.TaskSchdCoverageNugetNuget
uianimation.dllVanara.PInvoke.UIAnimationCoverageNugetNuget
uiautomationcore.dllVanara.PInvoke.UIAutomationCoverageNugetNuget
UrlMon.dllVanara.PInvoke.UrlMonCoverageNugetNuget
user32.dllVanara.PInvoke.User32CoverageNugetNuget
UserEnv.dllVanara.PInvoke.UserEnvCoverageNugetNuget
usp10.dllVanara.PInvoke.Usp10CoverageNugetNuget
uxtheme.dllVanara.PInvoke.UxThemeCoverageNugetNuget
Version.dllVanara.PInvoke.VersionCoverageNugetNuget
virtdisk.dllVanara.PInvoke.VirtDiskCoverageNugetNuget
vssapi.dllVanara.PInvoke.VssApiCoverageNugetNuget
WcmApi.dllVanara.PInvoke.WcmApiCoverageNugetNuget
wcnapi.dllVanara.PInvoke.WcnApiCoverageNugetNuget
websocket.dllVanara.PInvoke.WebSocketCoverageNugetNuget
wer.dllVanara.PInvoke.WerCoverageNugetNuget
WinBio.dllVanara.PInvoke.WinBioCoverageNugetNuget
winhttp.dllVanara.PInvoke.WinHTTPCoverageNugetNuget
wininet.dllVanara.PInvoke.WinINetCoverageNugetNuget
winscard.dllVanara.PInvoke.WinSCardCoverageNugetNuget
winspool.drv, prntvpt.dllVanara.PInvoke.PrintingCoverageNugetNuget
wintrust.dllVanara.PInvoke.WinTrustCoverageNugetNuget
WlanApi.dll, Wlanui.dllVanara.PInvoke.WlanApiCoverageNugetNuget
ws2_32.dllVanara.PInvoke.Ws2_32CoverageNugetNuget
wscapi.dllVanara.PInvoke.WscApiCoverageNugetNuget
wslapi.dllVanara.PInvoke.WslApiCoverageNugetNuget
WsmSvc.dllVanara.PInvoke.WsmSvcCoverageNugetNuget
WTSApi32.dllVanara.PInvoke.WTSApi32CoverageNugetNuget
wuapi.dllVanara.PInvoke.WUApiCoverageNugetNuget

Supporting Assemblies

Assembly   NuGet Link   Description
Vanara.CoreNugetNugetThis library includes shared methods, structures and constants for use throughout the Vanara assemblies. Think of it as windows.h with some useful extensions. It includes:
  • Extension methods for working with enumerated types (enum), FILETIME, and method and property extractions via reflection
  • Extension and helper methods to marshaling structures arrays and strings
  • SafeHandle based classes for working with memory allocated via CoTaskMem, HGlobal, or Local calls that handles packing and extracting arrays, structures and raw memory
  • Safe pinning of objects in memory
  • Memory stream based on marshaled memory
Vanara.BITSNugetNugetComplete .NET coverage of Windows BITS (Background Intelligent Transfer Service) functionality. Provides access to all library functions through Windows 11 and gracefully fails when new features are not available on older OS versions.
Vanara.DirectoryServicesNugetNugetWrapper classes around Win32 ADs methods and interfaces to provide simplified and object-oriented access to Active Directory and other directory service calls.
Vanara.ManagementNugetNugetExtensions and helper classes for System.Management.
Vanara.NetNugetNugetAbstracted classes around Win32 networking functions to provide simplified and object-oriented access to key networking capabilities like DNS, DHCP, filtering, access, and discovery.
Vanara.PInvoke.DirectXNugetNugetPInvoke API (methods, interfaces, structures and constants) imported from DirectX.
Vanara.PInvoke.DirectXMathNugetNugetPInvoke API (methods, structures and constants) imported from Windows DirectX Math.
Vanara.PInvoke.SharedNugetNugetShared methods, structures and constants for use throughout the Vanara.PInvoke assemblies. Includes:
  • IEnumerable helpers for COM enumerations
  • Custom marshaler for CoTaskMem pointers
  • Enhanced error results classes for HRESULT, Win32Error and NTStatus
  • Standard windows.h macros (e.g. HIWORD, MAKELONG, etc.)
  • Overlapped method wrapper
  • Resource ID holder
  • Shared structures and enums (see release notes)
Vanara.PInvoke.SpellCheckingApiNugetNugetPInvoke API (methods, structures and constants) imported from Windows Spell Checking API.
Vanara.SecurityNugetNugetClasses for security related items derived from the Vanara PInvoke libraries. Includes extension methods for Active Directory and access control classes, methods for working with accounts, UAC, privileges, system access, impersonation and SIDs, and a full LSA wrapper.
Vanara.SystemServicesNugetNugetClasses for system related items derived from the Vanara PInvoke libraries. Includes extensions for Process (privileges and elavation), FileInfo (compression info), Shared Network Drives and Devices, and ServiceController (SetStartType) that pull extended information through native API calls.
Vanara.VirtualDiskNugetNuget.NET classes to manage Windows Virtual Storage (VHD and VHDX) using P/Invoke functions from VirtDisk.dll.
Vanara.Windows.ExtensionsNugetNugetExtension methods and conversions from Vanara P/Invoke types and methods to Windows Forms types and methods.
Vanara.Windows.FormsNugetNugetClasses for user interface related items derived from the Vanara PInvoke libraries. Includes extensions for almost all common controls to give post Vista capabilities, WinForms controls (panel, commandlink, enhanced combo boxes, IPAddress, split button, trackbar and themed controls), shutdown/restart/lock control, buffered painting, resource files, access control editor, simplifed designer framework for Windows.Forms.
Vanara.Windows.Shell.CommonNugetNugetCommon classes for Windows Shell items derived from the Vanara PInvoke libraries. Includes shell items, files, icons, links, and taskbar lists.
Vanara.Windows.ShellNugetNugetClasses for Windows Shell items derived from the Vanara PInvoke libraries. Includes shell items, files, icons, links, and taskbar lists.
Vanara.WinUI.ExtensionsNugetNugetExtension methods and conversions from Vanara P/Invoke types and methods to UWP and WinUI types and methods.
Vanara.WPF.ExtensionsNugetNugetExtension methods and conversions from Vanara P/Invoke types and methods to WPF types and methods.

Quick Links

Sample Code

There are numerous examples in theUnitTest folder and in theWinClassicSamplesCS project that recreates the Windows Samples in C# using Vanara.

About

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp