Home

Awesome

Vanara

Version Downloads Build 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, .NET Standard 2.0, Core 3.1 and support SourceLink. 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 the Releases section and all NuGet packages are published to nuget.org. Each GitHub push triggers an AppVeyor build. The owners thank them for the free Open-Source account! The status of that build is in the header of this page. The NuGet packages from those builds are available for test purposes on AppVeyor's project NuGet source at https://ci.appveyor.com/nuget/vanara-prerelease.

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 directly var 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 the Supporting 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

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.dll, dxgi.dll, dwrite.dll, windowscodecs.dllVanara.PInvoke.GraphicsCoverageNugetNuget
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
dwmapi.dllVanara.PInvoke.DwmApiCoverageNugetNuget
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.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.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:<br><ul><li>Extension methods for working with enumerated types (enum), FILETIME, and method and property extractions via reflection</li><li>Extension and helper methods to marshaling structures arrays and strings</li><li>SafeHandle based classes for working with memory allocated via CoTaskMem, HGlobal, or Local calls that handles packing and extracting arrays, structures and raw memory</li><li>Safe pinning of objects in memory</li><li>Memory stream based on marshaled memory</li></ul>
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.SharedNugetNugetShared methods, structures and constants for use throughout the Vanara.PInvoke assemblies. Includes:<br><ul><li>IEnumerable helpers for COM enumerations</li><li>Custom marshaler for CoTaskMem pointers</li><li>Enhanced error results classes for HRESULT, Win32Error and NTStatus</li><li>Standard windows.h macros (e.g. HIWORD, MAKELONG, etc.)</li><li>Overlapped method wrapper</li><li>Resource ID holder</li><li>Shared structures and enums (see release notes)</li></ul>
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 the UnitTest folder and in the WinClassicSamplesCS project that recreates the Windows Samples in C# using Vanara.