mirror of https://github.com/dahall/Vanara.git
8a1c33e158 | ||
---|---|---|
Core | ||
HelpBuilder | ||
PInvoke | ||
Security | ||
System | ||
UnitTests | ||
WIndows.Forms | ||
Windows.Shell | ||
docs/icons | ||
.gitattributes | ||
.gitignore | ||
LICENSE | ||
README.md | ||
Vanara.sln |
README.md
In a number of projects I have needed to use native API calls. Over the years I have collected quite a few of these interop code chunks and I decided to pull them all together into a set of reusable libraries. I have tried to carve up the libraries into small enough chunks that they are easy to identify and consume. The only problem with this is that you can literally end up with over 20 dependencies on some of the higher function libraries (oh well).
I have tried to follow the concepts below in laying out the libraries.
- 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 assembly
Vanara.PInvoke.Gdi32.dll
hosts all functions and supporting enumerations, constants and structures that are exported fromgdi32.dll
in the system directory.)
- (e.g. The assembly
- Any structure or macro or enumeration (no function) that is used by many libraries is put into either
Vanara.Core
orVanara.PInvoke.Shared
- (e.g. The macro
HIWORD
and the structureSIZE
are both inVanara.PInvoke.Shared
and classes to simplfy interop calls and native memory management are inVanara.Core
.)
- (e.g. The macro
- 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 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.)
- Where the direct interpretation of a structure leads to memory leaks or misuse, I have tried to simplify their use
- Where structures are always passed by reference and where that structure needs to clean up memory allocations, I have changed the structure to class implementing
IDisposable
. - Wherever possible, all handles have been turned into
SafeHandle
derivatives. - 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 by
Vanara.PInvoke
- 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 and UI.
Quick Links
Installation
This project's assemblies are available via NuGet.
Sample Code
There are numerous examples in the UnitTest folder.