DllImportX 0.0.1
The open implementation of dynamic unmanaged imports for .NET ( DllImportX )
Install-Package DllImportX -Version 0.0.1
dotnet add package DllImportX --version 0.0.1
<PackageReference Include="DllImportX" Version="0.0.1" />
paket add DllImportX --version 0.0.1
DllImportX is an attribute to work around the classic DllImport's limitations.
The .Net platform does not allow to define dynamic values in the attributes
assignments to perform environment based unmanaged library linking.
With DllImporX, you can dynamically set the DllImport attribute at runtime
changing everyone attributes as necessary!
DllImportX's attribute supports all the classic DllImport parameters.
All you need is add the 'X' in the DllImport attribute and build your instance.
How to use
If you have an unmanaged static-link library with this functions:
// sample.h
// Unmanaged C sample functions
void cVoidSample();
int cIntSample(int intParam);
void cOutIntSample(int* outIntParam);
void cRefIntSample(int* refIntParam);
void cAnsiStringSample(const char* str);
void cPtrSample(void* ptr);
You must only define an interface in your project:
// ISample.cs
using System;
using System.Runtime.InteropServices;
namespace DllImportXSample
{
public interface ISample
{
[DllImportX("Sample.dll")]
void cVoidSample();
[DllImportX("Sample.dll")]
int cIntSample(int intParam);
[DllImportX("Sample.dll", EntryPoint = "cOutIntSample")]
void OutIntSample(out int outIntParam);
[DllImportX("Sample.dll", EntryPoint = "cRefIntSample"))]
void cRefIntSample(ref int refIntParam);
[DllImportX("Sample.dll", EntryPoint = "cAnsiString"))]
void AnsiStringSample([In][MarshalAs(UnmanagedType.LPStr)] string str);
[DllImportX("Sample.dll")]
void cPtrSample(IntPtr ptr);
}
}
And build your instance!
using System.Runtime.InteropServices;
using DllImportXSample;
// ...
var sampleInstance = DllImportXFactory
.Build<ISample>(entry => {
// Change the path to the unmanged static-link library
// based in the runtime enviroment architeture
entry.DllName = (IntPtr.Size == 8 ? "x64/" : "x86/") + entry.DllName;
});
// ready
sampleInstance.AnsiStringSample("Hello world.");
// ...
Bug Reports
If you find any bug, please report them using the GitHub issue tracker.
License
This software is distributed under the terms of the MIT license.
DllImportX is an attribute to work around the classic DllImport's limitations.
The .Net platform does not allow to define dynamic values in the attributes
assignments to perform environment based unmanaged library linking.
With DllImporX, you can dynamically set the DllImport attribute at runtime
changing everyone attributes as necessary!
DllImportX's attribute supports all the classic DllImport parameters.
All you need is add the 'X' in the DllImport attribute and build your instance.
How to use
If you have an unmanaged static-link library with this functions:
// sample.h
// Unmanaged C sample functions
void cVoidSample();
int cIntSample(int intParam);
void cOutIntSample(int* outIntParam);
void cRefIntSample(int* refIntParam);
void cAnsiStringSample(const char* str);
void cPtrSample(void* ptr);
You must only define an interface in your project:
// ISample.cs
using System;
using System.Runtime.InteropServices;
namespace DllImportXSample
{
public interface ISample
{
[DllImportX("Sample.dll")]
void cVoidSample();
[DllImportX("Sample.dll")]
int cIntSample(int intParam);
[DllImportX("Sample.dll", EntryPoint = "cOutIntSample")]
void OutIntSample(out int outIntParam);
[DllImportX("Sample.dll", EntryPoint = "cRefIntSample"))]
void cRefIntSample(ref int refIntParam);
[DllImportX("Sample.dll", EntryPoint = "cAnsiString"))]
void AnsiStringSample([In][MarshalAs(UnmanagedType.LPStr)] string str);
[DllImportX("Sample.dll")]
void cPtrSample(IntPtr ptr);
}
}
And build your instance!
using System.Runtime.InteropServices;
using DllImportXSample;
// ...
var sampleInstance = DllImportXFactory
.Build<ISample>(entry => {
// Change the path to the unmanged static-link library
// based in the runtime enviroment architeture
entry.DllName = (IntPtr.Size == 8 ? "x64/" : "x86/") + entry.DllName;
});
// ready
sampleInstance.AnsiStringSample("Hello world.");
// ...
Bug Reports
If you find any bug, please report them using the GitHub issue tracker.
License
This software is distributed under the terms of the MIT license.
Dependencies
-
.NETFramework 3.5
- No dependencies.
-
.NETStandard 1.5
- NETStandard.Library (>= 1.6.1)
- System.Reflection.Emit (>= 4.3.0)
Used By
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DllImportX:
Package | Downloads |
---|---|
Neoload.Ranorex
This package is a Neoload Ranorex Plugin. For more information see https://github.com/Neotys-Labs/Ranorex
|
GitHub repositories
This package is not used by any popular GitHub repositories.
Version History
Version | Downloads | Last updated |
---|---|---|
0.0.1 | 1,457 | 8/23/2017 |