仓库地址:https://github.com/dahall/Vanara
一系列非常简单易用,对Windows API做了极好封装的.NET类库,几乎不用再写繁琐的Windows API转换函数了。
此项目包含各种.NET程序集,这些程序集包含来自Windows库的P/Invoke函数、接口、枚举和结构。每个程序集都与一个或几个紧密相关的库相关联。例如,Shlwapi.dll包含从Shlwapi.lib导出的所有函数;Kernel32.dll包含Kernel32.lib和kernelbase.lib的全部。
所有程序集都可通过NuGet获得,并提供针对.NET 2.0、3.5、4.0、4.5、Core 3.0、Core 3.1和.NET 5.0(v3.2.20中新增)的版本,并支持SourceLink[1]。在依赖项不允许的所有情况下,.NET Standard 2.0、.NET Core 2.0和2.1版本也包含在UWP和其他.NET Core及标准项目中。
在充分测试之后,这个项目每隔几周发布一次新版本。新的版本和发行说明一起被编目在Releases[2]部分,所有NuGet包都发布到nuget.org[3]。每个GitHub推送都会触发AppVeyor[4]构建。所有者感谢他们的免费开源帐户!文章开头显示了项目构建状态信息。AppVeyor源[5]用于构建NuGet包。
var bret = Vanara.PInvoke.Kernel32.GetComputerName(sb, ref sbSz);
using static Vanara.PInvoke.Kernel32;
var bret = GetComputerName(sb, ref sbSz);
5.在某些情况下,其中一个[支持程序集]中有一个对应的helper/wrapper类,特别是对于安全性、系统服务、窗体和Shell。转到他们的库页面(单击部分中的链接),浏览每个库中包含的类。
Vanara.PInvoke.Gdi32.dll
承载系统目录中从gdi32.dll
导出的所有函数和支持的枚举、常量和结构。)Vanara.Core
或'Vanara.PInvoke.Shared`库中。HIWORD'和结构
SIZE都在
Vanara.PInvoke.Shared中,简化互操作调用和本机内存管理的类都在'Vanara.Core
中)Vanara.PInvoke.Kernel32
项目目录中,您将分别找到一个FileApi.cs、WinBase.cs和一个WinNT.cs文件,分别表示FileApi.h、WinBase.h和WinNT.h)IDispoable
的类。SafeHandle
派生工具。如果这些句柄需要调用函数以释放/关闭/销毁,则存在一个派生的SafeHANDLE
,该函数将在disposal时执行该函数。HTOKEN
。SafeHTOKEN
在该句柄上调用CloseHandle
自动释放。in
语句封装该结构体,该语句将通过引用传递结构体,而不需要ref
关键字。BOOL MapDialogRect(HWND hDlg, LPRECT LPRECT)
bool MapDialogRect(HWND hDlg, in RECT lpRect);
Library/DLL | Assembly |
---|---|
aclui.dll | Vanara.PInvoke.AclUI[6] |
advapi32.dll, secur32.dll, authz.dll, sspicli.dll, schannel.dll | Vanara.PInvoke.Security[7] |
cabinet.dll | Vanara.PInvoke.Cabinet[8] |
CfgMgr32.dll | Vanara.PInvoke.CfgMgr32[9] |
CldApi.dll | Vanara.PInvoke.CldApi[10] |
comctl32.dll | Vanara.PInvoke.ComCtl32[11] |
ComDlg32.dll | Vanara.PInvoke.ComDlg32[12] |
credui.dll | Vanara.PInvoke.CredUI[13] |
crypt32.dll, bcrypt.dll, ncrypt.dll, tokenbinding.dll, cryptui.dll, cryptnet.dll, cryptdlg.dll | Vanara.PInvoke.Cryptography[14] |
d2d1.dll, dxgi.dll, dwrite.dll, windowscodecs.dll | Vanara.PInvoke.Graphics[15] |
DbgHelp.dll, ImageHlp.dll | Vanara.PInvoke.DbgHelp[16] |
Dhcpcsvc6.dll, Dhcpcsvc.dll | Vanara.PInvoke.Dhcp[17] |
DnsApi.dll | Vanara.PInvoke.DnsApi[18] |
Drt.dll | Vanara.PInvoke.Drt[19] |
dwmapi.dll | Vanara.PInvoke.DwmApi[20] |
FirewallApi.dll | Vanara.PInvoke.FirewallApi[21] |
FunDisc.dll | Vanara.PInvoke.FunDisc[22] |
gdi32.dll | Vanara.PInvoke.Gdi32[23] |
imapi2.dll, imapi2fs.dll | Vanara.PInvoke.IMAPI[24] |
iphlpapi.dll | Vanara.PInvoke.IpHlpApi[25] |
IScsiDsc.dll | Vanara.PInvoke.IScsiDsc[26] |
kernel32.dll, kernelbase.dll, normaliz.dll, vertdll.dll | Vanara.PInvoke.Kernel32[27] |
ktmw32.dll | Vanara.PInvoke.KtmW32[28] |
Lz32.dll | Vanara.PInvoke.Lz32[29] |
magnification.dll | Vanara.PInvoke.Magnification[30] |
mpr.dll | Vanara.PInvoke.Mpr[31] |
msctf.dll, input.dll, msimtf.dll | Vanara.PInvoke.TextServicesFramework[32] |
Msi.dll | Vanara.PInvoke.Msi[33] |
avicap32.dll, avifil32.dll, msacm32.dll, msvfw32.dll, winmm.dll | Vanara.PInvoke.Multimedia[34] |
netapi32.dll | Vanara.PInvoke.NetApi32[35] |
netprofm.dll | Vanara.PInvoke.NetListMgr[36] |
NewDev.dll | Vanara.PInvoke.NewDev[37] |
ntdll.dll | Vanara.PInvoke.NTDll[38] |
ntdsapi.dll | Vanara.PInvoke.NTDSApi[39] |
ole32.dll, oleaut32.dll, propsys.dll | Vanara.PInvoke.Ole[40] |
oleacc.dll | Vanara.PInvoke.Accessibility[41] |
OleDlg.dll | Vanara.PInvoke.OleDlg[42] |
opcservices.dll | Vanara.PInvoke.Opc[43] |
P2P.dll | Vanara.PInvoke.P2P[44] |
pdh.dll | Vanara.PInvoke.Pdh[45] |
PeerDist.dll | Vanara.PInvoke.PeerDist[46] |
powrprof.dll | Vanara.PInvoke.PowrProf[47] |
ProjectedFSLib.dll | Vanara.PInvoke.ProjectedFSLib[48] |
qmgr.dll | Vanara.PInvoke.BITS[49] |
rpcrt4.dll | Vanara.PInvoke.Rpc[50] |
RstrtMgr.dll | Vanara.PInvoke.RstrtMgr[51] |
SearchApi | Vanara.PInvoke.SearchApi[52] |
SetupAPI.dll | Vanara.PInvoke.SetupAPI[53] |
SHCore.dll | Vanara.PInvoke.SHCore[54] |
shell32.dll, url.dll | Vanara.PInvoke.Shell32[55] |
shlwapi.dll | Vanara.PInvoke.ShlwApi[56] |
taskschd.dll, mstask.dll | Vanara.PInvoke.TaskSchd[57] |
UrlMon.dll | Vanara.PInvoke.UrlMon[58] |
user32.dll | Vanara.PInvoke.User32[59] |
UserEnv.dll | Vanara.PInvoke.UserEnv[60] |
uxtheme.dll | Vanara.PInvoke.UxTheme[61] |
Version.dll | Vanara.PInvoke.Version[62] |
virtdisk.dll | Vanara.PInvoke.VirtDisk[63] |
WcmApi.dll | Vanara.PInvoke.WcmApi[64] |
WcnApi.dll | Vanara.PInvoke.WcnApi[65] |
wer.dll | Vanara.PInvoke.Wer[66] |
WinBio.dll | Vanara.PInvoke.WinBio[67] |
wininet.dll | Vanara.PInvoke.WinINet[68] |
winspool.drv, prntvpt.dll | Vanara.PInvoke.Printing[69] |
wintrust.dll | Vanara.PInvoke.WinTrust[70] |
WlanApi.dll, Wlanui.dll | Vanara.PInvoke.WlanApi[71] |
ws2_32.dll | Vanara.PInvoke.Ws2_32[72] |
WsmSvc.dll | Vanara.PInvoke.WsmSvc[73] |
WTSApi32.dll | Vanara.PInvoke.WTSApi32[74] |
Assembly | Description |
---|---|
Vanara.BITS[75] | .NET classes to access Background Intelligent Transfer Service (BITS) functionality. Intelligently uses most recent library functions and gracefully fails when new features are not available on older OS versions. |
Vanara.Core[76] | This 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.PInvoke.Shared[77] | Shared 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.Security[78] | Classes 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.SystemServices[79] | Classes 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.VirtualDisk[80] | .NET classes to manage Windows Virtual Storage (VHD and VHDX) using P/Invoke functions from VirtDisk.dll. |
Vanara.Windows.Forms[81] | Classes 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[82] | Classes for Windows Shell items derived from the Vanara PInvoke libraries. Includes shell items, files, icons, links, and taskbar lists. |
There are numerous examples in the UnitTest[85] folder and in the WinClassicSamplesCS[86] project that recreates the Windows Samples in C# using Vanara.
[1]
SourceLink: https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/sourcelink
[2]
Releases: https://github.com/dahall/Vanara/releases
[3]
nuget.org: https://www.nuget.org/packages?q=dahall+Vanara
[4]
AppVeyor: https://ci.appveyor.com/project/dahall/vanara
[5]
AppVeyor源: https://ci.appveyor.com/nuget/vanara-prerelease
[6]
Vanara.PInvoke.AclUI: https://github.com/dahall/Vanara/blob/master/PInvoke/AclUI/CorrelationReport.md
[7]
Vanara.PInvoke.Security: https://github.com/dahall/Vanara/blob/master/PInvoke/Security/CorrelationReport.md
[8]
Vanara.PInvoke.Cabinet: https://github.com/dahall/Vanara/blob/master/PInvoke/Cabinet/CorrelationReport.md
[9]
Vanara.PInvoke.CfgMgr32: https://github.com/dahall/Vanara/blob/master/PInvoke/CfgMgr32/CorrelationReport.md
[10]
Vanara.PInvoke.CldApi: https://github.com/dahall/Vanara/blob/master/PInvoke/CldApi/CorrelationReport.md
[11]
Vanara.PInvoke.ComCtl32: https://github.com/dahall/Vanara/blob/master/PInvoke/ComCtl32/CorrelationReport.md
[12]
Vanara.PInvoke.ComDlg32: https://github.com/dahall/Vanara/blob/master/PInvoke/ComDlg32/CorrelationReport.md
[13]
Vanara.PInvoke.CredUI: https://github.com/dahall/Vanara/blob/master/PInvoke/CredUI/CorrelationReport.md
[14]
Vanara.PInvoke.Cryptography: https://github.com/dahall/Vanara/blob/master/PInvoke/Cryptography/CorrelationReport.md
[15]
Vanara.PInvoke.Graphics: https://github.com/dahall/Vanara/blob/master/PInvoke/Graphics/CorrelationReport.md
[16]
Vanara.PInvoke.DbgHelp: https://github.com/dahall/Vanara/blob/master/PInvoke/DbgHelp/CorrelationReport.md
[17]
Vanara.PInvoke.Dhcp: https://github.com/dahall/Vanara/blob/master/PInvoke/Dhcp/CorrelationReport.md
[18]
Vanara.PInvoke.DnsApi: https://github.com/dahall/Vanara/blob/master/PInvoke/DnsApi/CorrelationReport.md
[19]
Vanara.PInvoke.Drt: https://github.com/dahall/Vanara/blob/master/PInvoke/Drt/CorrelationReport.md
[20]
Vanara.PInvoke.DwmApi: https://github.com/dahall/Vanara/blob/master/PInvoke/DwmApi/CorrelationReport.md
[21]
Vanara.PInvoke.FirewallApi: https://github.com/dahall/Vanara/blob/master/PInvoke/FirewallApi/CorrelationReport.md
[22]
Vanara.PInvoke.FunDisc: https://github.com/dahall/Vanara/blob/master/PInvoke/FunDisc/CorrelationReport.md
[23]
Vanara.PInvoke.Gdi32: https://github.com/dahall/Vanara/blob/master/PInvoke/Gdi32/CorrelationReport.md
[24]
Vanara.PInvoke.IMAPI: https://github.com/dahall/Vanara/blob/master/PInvoke/IMAPI/CorrelationReport.md
[25]
Vanara.PInvoke.IpHlpApi: https://github.com/dahall/Vanara/blob/master/PInvoke/IpHlpApi/CorrelationReport.md
[26]
Vanara.PInvoke.IScsiDsc: https://github.com/dahall/Vanara/blob/master/PInvoke/IScsiDsc/CorrelationReport.md
[27]
Vanara.PInvoke.Kernel32: https://github.com/dahall/Vanara/blob/master/PInvoke/Kernel32/CorrelationReport.md
[28]
Vanara.PInvoke.KtmW32: https://github.com/dahall/Vanara/blob/master/PInvoke/KtmW32/CorrelationReport.md
[29]
Vanara.PInvoke.Lz32: https://github.com/dahall/Vanara/blob/master/PInvoke/Lz32/CorrelationReport.md
[30]
Vanara.PInvoke.Magnification: https://github.com/dahall/Vanara/blob/master/PInvoke/Magnification/CorrelationReport.md
[31]
Vanara.PInvoke.Mpr: https://github.com/dahall/Vanara/blob/master/PInvoke/Mpr/CorrelationReport.md
[32]
Vanara.PInvoke.TextServicesFramework: https://github.com/dahall/Vanara/blob/master/PInvoke/TextServicesFramework/CorrelationReport.md
[33]
Vanara.PInvoke.Msi: https://github.com/dahall/Vanara/blob/master/PInvoke/Msi/CorrelationReport.md
[34]
Vanara.PInvoke.Multimedia: https://github.com/dahall/Vanara/blob/master/PInvoke/Multimedia/CorrelationReport.md
[35]
Vanara.PInvoke.NetApi32: https://github.com/dahall/Vanara/blob/master/PInvoke/NetApi32/CorrelationReport.md
[36]
Vanara.PInvoke.NetListMgr: https://github.com/dahall/Vanara/blob/master/PInvoke/NetListMgr/CorrelationReport.md
[37]
Vanara.PInvoke.NewDev: https://github.com/dahall/Vanara/blob/master/PInvoke/NewDev/CorrelationReport.md
[38]
Vanara.PInvoke.NTDll: https://github.com/dahall/Vanara/blob/master/PInvoke/NtDll/CorrelationReport.md
[39]
Vanara.PInvoke.NTDSApi: https://github.com/dahall/Vanara/blob/master/PInvoke/NTDSApi/CorrelationReport.md
[40]
Vanara.PInvoke.Ole: https://github.com/dahall/Vanara/blob/master/PInvoke/Ole/CorrelationReport.md
[41]
Vanara.PInvoke.Accessibility: https://github.com/dahall/Vanara/blob/master/PInvoke/Accessibility/CorrelationReport.md
[42]
Vanara.PInvoke.OleDlg: https://github.com/dahall/Vanara/blob/master/PInvoke/OleDlg/CorrelationReport.md
[43]
Vanara.PInvoke.Opc: https://github.com/dahall/Vanara/blob/master/PInvoke/Opc/CorrelationReport.md
[44]
Vanara.PInvoke.P2P: https://github.com/dahall/Vanara/blob/master/PInvoke/P2P/CorrelationReport.md
[45]
Vanara.PInvoke.Pdh: https://github.com/dahall/Vanara/blob/master/PInvoke/Pdh/CorrelationReport.md
[46]
Vanara.PInvoke.PeerDist: https://github.com/dahall/Vanara/blob/master/PInvoke/PeerDist/CorrelationReport.md
[47]
Vanara.PInvoke.PowrProf: https://github.com/dahall/Vanara/blob/master/PInvoke/PowrProf/CorrelationReport.md
[48]
Vanara.PInvoke.ProjectedFSLib: https://github.com/dahall/Vanara/blob/master/PInvoke/ProjectedFSLib/CorrelationReport.md
[49]
Vanara.PInvoke.BITS: https://github.com/dahall/Vanara/blob/master/PInvoke/BITS/CorrelationReport.md
[50]
Vanara.PInvoke.Rpc: https://github.com/dahall/Vanara/blob/master/PInvoke/Rpc/CorrelationReport.md
[51]
Vanara.PInvoke.RstrtMgr: https://github.com/dahall/Vanara/blob/master/PInvoke/RstrtMgr/CorrelationReport.md
[52]
Vanara.PInvoke.SearchApi: https://github.com/dahall/Vanara/blob/master/PInvoke/SearchApi/CorrelationReport.md
[53]
Vanara.PInvoke.SetupAPI: https://github.com/dahall/Vanara/blob/master/PInvoke/SetupAPI/CorrelationReport.md
[54]
Vanara.PInvoke.SHCore: https://github.com/dahall/Vanara/blob/master/PInvoke/SHCore/CorrelationReport.md
[55]
Vanara.PInvoke.Shell32: https://github.com/dahall/Vanara/blob/master/PInvoke/Shell32/CorrelationReport.md
[56]
Vanara.PInvoke.ShlwApi: https://github.com/dahall/Vanara/blob/master/PInvoke/ShlwApi/CorrelationReport.md
[57]
Vanara.PInvoke.TaskSchd: https://github.com/dahall/Vanara/blob/master/PInvoke/TaskSchd/CorrelationReport.md
[58]
Vanara.PInvoke.UrlMon: https://github.com/dahall/Vanara/blob/master/PInvoke/UrlMon/CorrelationReport.md
[59]
Vanara.PInvoke.User32: https://github.com/dahall/Vanara/blob/master/PInvoke/User32/CorrelationReport.md
[60]
Vanara.PInvoke.UserEnv: https://github.com/dahall/Vanara/blob/master/PInvoke/UserEnv/CorrelationReport.md
[61]
Vanara.PInvoke.UxTheme: https://github.com/dahall/Vanara/blob/master/PInvoke/UxTheme/CorrelationReport.md
[62]
Vanara.PInvoke.Version: https://github.com/dahall/Vanara/blob/master/PInvoke/Version/CorrelationReport.md
[63]
Vanara.PInvoke.VirtDisk: https://github.com/dahall/Vanara/blob/master/PInvoke/VirtDisk/CorrelationReport.md
[64]
Vanara.PInvoke.WcmApi: https://github.com/dahall/Vanara/blob/master/PInvoke/WcmApi/CorrelationReport.md
[65]
Vanara.PInvoke.WcnApi: https://github.com/dahall/Vanara/blob/master/PInvoke/WcnApi/CorrelationReport.md
[66]
Vanara.PInvoke.Wer: https://github.com/dahall/Vanara/blob/master/PInvoke/Wer/CorrelationReport.md
[67]
Vanara.PInvoke.WinBio: https://github.com/dahall/Vanara/blob/master/PInvoke/WinBio/CorrelationReport.md
[68]
Vanara.PInvoke.WinINet: https://github.com/dahall/Vanara/blob/master/PInvoke/WinINet/CorrelationReport.md
[69]
Vanara.PInvoke.Printing: https://github.com/dahall/Vanara/blob/master/PInvoke/Printing/CorrelationReport.md
[70]
Vanara.PInvoke.WinTrust: https://github.com/dahall/Vanara/blob/master/PInvoke/WinTrust/CorrelationReport.md
[71]
Vanara.PInvoke.WlanApi: https://github.com/dahall/Vanara/blob/master/PInvoke/WlanApi/CorrelationReport.md
[72]
Vanara.PInvoke.Ws2_32: https://github.com/dahall/Vanara/blob/master/PInvoke/Ws2_32/CorrelationReport.md
[73]
Vanara.PInvoke.WsmSvc: https://github.com/dahall/Vanara/blob/master/PInvoke/WsmSvc/CorrelationReport.md
[74]
Vanara.PInvoke.WTSApi32: https://github.com/dahall/Vanara/blob/master/PInvoke/WTSApi32/CorrelationReport.md
[75]
Vanara.BITS: https://github.com/dahall/Vanara/blob/master/BITS/AssemblyReport.md
[76]
Vanara.Core: https://github.com/dahall/Vanara/blob/master/Core/AssemblyReport.md
[77]
Vanara.PInvoke.Shared: https://github.com/dahall/Vanara/blob/master/PInvoke/Shared/AssemblyReport.md
[78]
Vanara.Security: https://github.com/dahall/Vanara/blob/master/Security/AssemblyReport.md
[79]
Vanara.SystemServices: https://github.com/dahall/Vanara/blob/master/System/AssemblyReport.md
[80]
Vanara.VirtualDisk: https://github.com/dahall/Vanara/blob/master/VirtualDisk/AssemblyReport.md
[81]
Vanara.Windows.Forms: https://github.com/dahall/Vanara/blob/master/Windows.Forms/AssemblyReport.md
[82]
Vanara.Windows.Shell: https://github.com/dahall/Vanara/blob/master/Windows.Shell/AssemblyReport.md
[83]
Documentation: https://github.com/dahall/Vanara/wiki
[84]
Issues: https://github.com/dahall/Vanara/issues
[85]
UnitTest: https://github.com/dahall/Vanara/tree/master/UnitTests
[86]
WinClassicSamplesCS: https://github.com/dahall/WinCla