Vanara/README.md

89 lines
15 KiB
Markdown
Raw Normal View History

2017-12-05 22:44:23 -05:00
![Vanara](/docs/icons/VanaraHeading.png)
2018-08-10 13:54:00 -04:00
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 2.0, 3.5, 4.0 and 4.5. In all cases where a dependency doesn't disallow it, a .NET Standard 2.0 build is also included for use with UWP and other .NET Core and Standard projects.
## Use
1. Look for the function you need in Microsoft documentation. Note which library or DLL the function is in.
2018-08-18 23:37:35 -04:00
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.
2018-08-10 13:54:00 -04:00
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);
```
## Design Concepts
2017-12-05 22:44:23 -05:00
I have tried to follow the concepts below in laying out the libraries.
2018-12-01 13:32:55 -05:00
* All functions that are imported from a single DLL should be placed into a single assembly that is named after the DLL.
2017-12-05 22:44:23 -05:00
* (e.g. The assembly `Vanara.PInvoke.Gdi32.dll` hosts all functions and supporting enumerations, constants and structures that are exported from `gdi32.dll` in the system directory.)
2018-12-01 13:32:55 -05:00
* Any structure or macro or enumeration (no function) that is used by many libraries is put into either `Vanara.Core` or `Vanara.PInvoke.Shared`.
2017-12-05 22:44:23 -05:00
* (e.g. The macro `HIWORD` and the structure `SIZE` are both in `Vanara.PInvoke.Shared` and classes to simplfy interop calls and native memory management are in `Vanara.Core`.)
2018-12-01 13:32:55 -05:00
* 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.
2017-12-05 22:44:23 -05:00
* (e.g. In the Vanara.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.)
2018-12-01 13:32:55 -05:00
* Where the direct interpretation of a structure leads to memory leaks or misuse, I have tried to simplify their use.
2018-01-08 11:51:37 -05:00
* Where structures are always passed by reference and where that structure needs to clean up memory allocations, I have changed the structure to a class implementing `IDisposable`.
2018-09-22 01:40:22 -04:00
* Wherever possible, all handles have been turned into `SafeHandle` derivatives named after the Windows API handle. If those handles require a call to a function to release/close/destroy, a derived `SafeHANDLE` exists that performs that function on disposal.
2018-12-01 13:32:55 -05:00
* e.g. `HTOKEN` is defined. `SafeHTOKEN` builds upon that handle with an automated release calling `CloseHandle`.
2017-12-05 22:44:23 -05:00
* Wherever possible, all functions that allocate memory that is to be freed by the caller use a safe memory handle.
2018-12-01 13:32:55 -05:00
* All PInvoke calls are in assemblies prefixed by `Vanara.PInvoke`.
* If a structure is to passed into a function, that structure is marshaled using the `in` statement which will pass the structure by reference without requiring the `ref` keyword.
2018-09-22 01:40:22 -04:00
* Windows API: `BOOL MapDialogRect(HWND hDlg, LPRECT lpRect)`
2018-12-01 13:32:55 -05:00
* Vanara: `bool MapDialogRect(HWND hDlg, in RECT lpRect);`
2018-01-08 11:51:37 -05:00
* If there are classes or extensions that make use of the PInvoke calls, they are in wrapper assemblies prefixed by `Vanara` and then followed by a logical name for the functionality. Today, those are Core, Security, SystemServices, Windows.Forms and Windows.Shell.
2017-12-05 22:44:23 -05:00
2018-08-10 13:54:00 -04:00
## Supported Libraries
2019-02-19 16:04:41 -05:00
Library/DLL | Assembly | Coverage | NuGet Link
2019-02-20 09:29:39 -05:00
--- | --- | --- | ---
2019-02-20 09:40:06 -05:00
*Core* (see Supporting Assemblies) | [Vanara.Core](https://github.com/dahall/Vanara/blob/master/Core/AssemblyReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.Core)](https://www.nuget.org/packages/Vanara.Core)
*Shared* (see Supporting Assemblies) | [Vanara.PInvoke.Shared](https://github.com/dahall/Vanara/blob/master/PInvoke/Shared/AssemblyReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.Shared)](https://www.nuget.org/packages/Vanara.PInvoke.Shared)
2019-02-19 16:04:41 -05:00
AclUI.dll | [Vanara.PInvoke.AclUI](https://github.com/dahall/Vanara/blob/master/PInvoke/AclUI/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.AclUI)](https://www.nuget.org/packages/Vanara.PInvoke.AclUI)
qmgr.dll (BITS) | [Vanara.PInvoke.BITS](https://github.com/dahall/Vanara/blob/master/PInvoke/BITS/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.BITS)](https://www.nuget.org/packages/Vanara.PInvoke.BITS)
ComCtl32.dll | [Vanara.PInvoke.ComCtl32](https://github.com/dahall/Vanara/blob/master/PInvoke/ComCtl32/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.ComCtl32)](https://www.nuget.org/packages/Vanara.PInvoke.ComCtl32)
CredUI.dll | [Vanara.PInvoke.CredUI](https://github.com/dahall/Vanara/blob/master/PInvoke/CredUI/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.CredUI)](https://www.nuget.org/packages/Vanara.PInvoke.CredUI)
BCrypt.dll, Crypt32.dll and NCrypt.dll | [Vanara.PInvoke.Cryptography](https://github.com/dahall/Vanara/blob/master/PInvoke/Cryptography/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/23%25-yellow.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.Cryptography)](https://www.nuget.org/packages/Vanara.PInvoke.Cryptography)
DwmApi.dll | [Vanara.PInvoke.DwmApi](https://github.com/dahall/Vanara/blob/master/PInvoke/DwmApi/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.DwmApi)](https://www.nuget.org/packages/Vanara.PInvoke.DwmApi)
Gdi32.dll | [Vanara.PInvoke.Gdi32](https://github.com/dahall/Vanara/blob/master/PInvoke/Gdi32/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/5%25-red.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.Gdi32)](https://www.nuget.org/packages/Vanara.PInvoke.Gdi32)
IpHlpApi.dll | [Vanara.PInvoke.IpHlpApi](https://github.com/dahall/Vanara/blob/master/PInvoke/IpHlpApi/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/60%25-yellow.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.IpHlpApi)](https://www.nuget.org/packages/Vanara.PInvoke.IpHlpApi)
Kernel32.dll and KernelBase.dll | [Vanara.PInvoke.Kernel32](https://github.com/dahall/Vanara/blob/master/PInvoke/Kernel32/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.Kernel32)](https://www.nuget.org/packages/Vanara.PInvoke.Kernel32)
Mpr.dll | [Vanara.PInvoke.Mpr](https://github.com/dahall/Vanara/blob/master/PInvoke/Mpr/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.Mpr)](https://www.nuget.org/packages/Vanara.PInvoke.Mpr)
NetApi32.dll | [Vanara.PInvoke.NetApi32](https://github.com/dahall/Vanara/blob/master/PInvoke/NetApi32/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.NetApi32)](https://www.nuget.org/packages/Vanara.PInvoke.NetApi32)
NetListMgr.dll | [Vanara.PInvoke.NetListMgr](https://github.com/dahall/Vanara/blob/master/PInvoke/NetListMgr/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.NetListMgr)](https://www.nuget.org/packages/Vanara.PInvoke.NetListMgr)
NTDSApi.dll | [Vanara.PInvoke.NTDSApi](https://github.com/dahall/Vanara/blob/master/PInvoke/NTDSApi/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-yellow.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.NTDSApi)](https://www.nuget.org/packages/Vanara.PInvoke.NTDSApi)
NTDll.dll | [Vanara.PInvoke.NTDll](https://github.com/dahall/Vanara/blob/master/PInvoke/NTDll/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/4%25-red.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.NTDll)](https://www.nuget.org/packages/Vanara.PInvoke.NTDll)
Ole32.dll, OleAut32 and PropSys.dll | [Vanara.PInvoke.Ole](https://github.com/dahall/Vanara/blob/master/PInvoke/Ole/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/27%25-yellow.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.Ole)](https://www.nuget.org/packages/Vanara.PInvoke.Ole)
AdvApi32.dll, Authz.dll and Secur32.dll | [Vanara.PInvoke.Security](https://github.com/dahall/Vanara/blob/master/PInvoke/Security/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/28%25-red.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.Security)](https://www.nuget.org/packages/Vanara.PInvoke.Security)
Shell32.dll | [Vanara.PInvoke.Shell32](https://github.com/dahall/Vanara/blob/master/PInvoke/Shell32/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.Shell32)](https://www.nuget.org/packages/Vanara.PInvoke.Shell32)
ShlwApi.dll | [Vanara.PInvoke.ShlwApi](https://github.com/dahall/Vanara/blob/master/PInvoke/ShlwApi/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.ShlwApi)](https://www.nuget.org/packages/Vanara.PInvoke.ShlwApi)
TaskSchd.dll and MSTask.dll | [Vanara.PInvoke.TaskSchd](https://github.com/dahall/Vanara/blob/master/PInvoke/TaskSchd/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.TaskSchd)](https://www.nuget.org/packages/Vanara.PInvoke.TaskSchd)
User32.dll | [Vanara.PInvoke.User32](https://github.com/dahall/Vanara/blob/master/PInvoke/User32/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/62%25-yellow.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.User32)](https://www.nuget.org/packages/Vanara.PInvoke.User32)
User32.dll that have GDI references | [Vanara.PInvoke.User32.Gdi](https://github.com/dahall/Vanara/blob/master/PInvoke/User32.Gdi/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/62%25-yellow.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.User32.Gdi)](https://www.nuget.org/packages/Vanara.PInvoke.User32.Gdi)
UxTheme.dll | [Vanara.PInvoke.UxTheme](https://github.com/dahall/Vanara/blob/master/PInvoke/UxTheme/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.UxTheme)](https://www.nuget.org/packages/Vanara.PInvoke.UxTheme)
VirtDisk.dll | [Vanara.PInvoke.VirtDisk](https://github.com/dahall/Vanara/blob/master/PInvoke/VirtDisk/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/100%25-green.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.VirtDisk)](https://www.nuget.org/packages/Vanara.PInvoke.VirtDisk)
WinINet.dll | [Vanara.PInvoke.WinINet](https://github.com/dahall/Vanara/blob/master/PInvoke/WinINet/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/8%25-red.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.WinINet)](https://www.nuget.org/packages/Vanara.PInvoke.WinINet)
Ws2_32.dll | [Vanara.PInvoke.Ws2_32](https://github.com/dahall/Vanara/blob/master/PInvoke/Ws2_32/CorrelationReport.md) | ![Coverage](https://img.shields.io/badge/3%25-red.svg) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.Ws2_32)](https://www.nuget.org/packages/Vanara.PInvoke.Ws2_32)
2018-08-10 13:54:00 -04:00
## Supporting Assemblies
2019-02-20 09:40:06 -05:00
Assembly |    NuGet Link    | Description
--- | --- | ---
2019-02-19 16:04:41 -05:00
[Vanara.Core](https://github.com/dahall/Vanara/blob/master/Core/AssemblyReport.md) | [![NuGet](https://buildstats.info/nuget/Vanara.Core)](https://www.nuget.org/packages/Vanara.Core) | Shared methods, structures and constants for use throughout the Vanara assemblies. Think of it as windows.h with some useful extensions.
[Vanara.PInvoke.Shared](https://github.com/dahall/Vanara/blob/master/PInvoke/Shared/AssemblyReport.md) | [![NuGet](https://buildstats.info/nuget/Vanara.PInvoke.Shared)](https://www.nuget.org/packages/Vanara.PInvoke.Shared) | Shared methods, structures and constants for use throughout the Vanara.PInvoke assemblies.
[Vanara.Security](https://github.com/dahall/Vanara/blob/master/Security/AssemblyReport.md) | [![NuGet](https://buildstats.info/nuget/Vanara.Security)](https://www.nuget.org/packages/Vanara.Security) | Classes for Windows Security that are missing or incomplete in .NET. Includes claims, privileges, impersonation, Active Directory, and UAC.
[Vanara.SystemServices](https://github.com/dahall/Vanara/blob/master/System/AssemblyReport.md) | [![NuGet](https://buildstats.info/nuget/Vanara.SystemServices)](https://www.nuget.org/packages/Vanara.SystemServices) | Classes for Windows system functions. Includes Background Transfer (BITS), Virtual Disk management, WOW64 interaction, and file, process, path, networking and service controller extensions.
[Vanara.Windows.Forms](https://github.com/dahall/Vanara/blob/master/WIndows.Forms/AssemblyReport.md) | [![NuGet](https://buildstats.info/nuget/Vanara.Windows.Forms)](https://www.nuget.org/packages/Vanara.Windows.Forms) | 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, simplified designer framework for Windows.Forms.
[Vanara.Windows.Shell](https://github.com/dahall/Vanara/blob/master/Windows.Shell/AssemblyReport.md) | [![NuGet](https://buildstats.info/nuget/Vanara.Windows.Shell)](https://www.nuget.org/packages/Vanara.Windows.Shell) | Classes for Windows Shell items derived from the Vanara PInvoke libraries. Includes shell items, files, icons, links, shell properties, shell registration and taskbar lists.
2018-08-10 13:54:00 -04:00
2017-12-05 22:44:23 -05:00
## Quick Links
2017-12-13 21:21:07 -05:00
* [Documentation](https://github.com/dahall/Vanara/wiki)
2017-12-05 22:44:23 -05:00
* [Issues](https://github.com/dahall/Vanara/issues)
## Sample Code
There are numerous examples in the [UnitTest](https://github.com/dahall/Vanara/tree/master/UnitTests) folder.