Binder of Unmanaged code for .NET
The Conari represents a flexible platform to work with unmanaged code, other native and binary data. The lightweight and powerful binding from any exported functions of libraries (a library or executable module), and more...
Did you know: The LunaRoad project works over Conari.
Easy to start:
using(IConari c = new ConariL("Library.dll")) {
// ...
}
Conari is ready for any exported functions immediately via:
- Dynamic features / DLR:
var ptr = d.test<IntPtr>(); // eqv: l.bind<Func<IntPtr>>("test")();
var codec = d.avcodec_find_encoder<IntPtr>(AV_CODEC_ID_MP2); // eqv: l.bind<Func<ulong, IntPtr>>("avcodec_find_encoder")(AV_CODEC_ID_MP2);
d.push(); // eqv: l.bind<Action>("push")();
It does not require the any configuration from you, we will do it automatically. Easy and works well.
- Lambda expressions:
using(var c = new ConariL("Library.dll"))
{
c.bind<Action<int, int>>("call")(2, 1);
double num = c.bind<Func<IntPtr, int, double>>("tonumber")(L, 4);
}
This also does not require the creation of any additional delegate. The Conari will do it automatically instead of you.
Just use bind<>
methods and have fun !
c.bind<...>("function")
// you already may invoke it immediately as above:
c.bind<Action<int, string>>("set")(-1, "Hello from Conari !");
// or later:
var set = c.bind<Action<int, string>>("set");
...
set(-1, "Hello from Conari !");
Lazy loading:
using(var l = new ConariL(
new Config("Library.dll") {
LazyLoading = true
}))
{
...
}
Native C/C++ structures without declaration [?]:
// IMAGE_FILE_HEADER: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680313.aspx
dynamic ifh = NativeData
._(data)
.t<WORD, WORD>(null, "NumberOfSections")
.align<DWORD>(3)
.t<WORD, WORD>("SizeOfOptionalHeader")
.Raw.Type;
if(ifh.SizeOfOptionalHeader == 0xE0) { // IMAGE_OPTIONAL_HEADER32
...
}
// IMAGE_DATA_DIRECTORY: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680305.aspx
dynamic idd = (new NativeData(data))
.t<DWORD>("VirtualAddress") // idd.VirtualAddress
.t<DWORD>("Size") // idd.Size
.Raw.Type;
Raw mt = NativeData
._(ptr)
.align<int>(2, "a", "b")
.t<IntPtr>("name")
.Raw;
- {byte[0x0000000c]} byte[]
[0] 0x05 byte --
[1] 0x00 byte |
[2] 0x00 byte |
[3] 0x00 byte --^ a = 5
[4] 0x07 byte --
[5] 0x00 byte |
[6] 0x00 byte |
[7] 0x00 byte --^ b = 7
[8] 0x20 byte --
[9] 0x78 byte |_ pointer to allocated string: (CharPtr)name
[10] 0xf0 byte |
[11] 0x56 byte --
...
Calling Convention & Name-Decoration [?]:
using(var l = new ConariL("Library.dll", CallingConvention.StdCall))
{
//...
l.Mangling = true; // _get_SevenStdCall@0 <-> get_SevenStdCall
l.Convention = CallingConvention.Cdecl;
}
Additional types:
- BSTR, CharPtr, float_t, int_t, ptrdiff_t, size_t, uint_t, WCharPtr
- UnmanagedString - to allocation of new unmanaged strings for your unmanaged code.
- ...
size_t len;
CharPtr name = c.bind<FuncOut3<int, size_t, IntPtr>>("to")(1, out len);
...
string myName += name; // (IntPtr)name; .Raw; .Ansi; .Utf8; ...
...
uint_t v = dll.getU(2);
Events:
l.ConventionChanged += (object sender, DataArgs<CallingConvention> e) =>
{
DLR = newDLR(e.Data);
LSender.Send(sender, $"DLR has been updated with new CallingConvention: {e.Data}", Message.Level.Info);
};
l.BeforeUnload += (object sender, DataArgs<Link> e) =>
{
// Do not forget to do something before unloading a library
};
...
and more ...
you wish, we doing
Copyright (c) 2016 Denis Kuzmin <entry.reg@gmail.com>
Available variants:
- NuGet PM:
Install-Package Conari
- GetNuTool:
msbuild gnt.core /p:ngpackages="Conari"
or gnt /p:ngpackages="Conari" - NuGet Commandline:
nuget install Conari
- /releases ( latest )
- Nightly builds (
/artifacts
page). But remember: It can be unstable or not work at all. Use this for tests of latest changes.