Either expose the methods as COM methods, or create a C++/CLI wrapper around them.
Shorten amount of DllImport in C#?
-
22-03-2022 - |
Question
Here is a sample of my C# code. Is there a way to decrease the amount of DllImport attributes?
namespace CSLib
{
class Program
{
static void Main(string[] args)
{
CLib.test();
CLib.test2(3);
A a = new A() { a = 9, b = 5 };
CLib.test3(ref a);
}
}
class CLib
{
[DllImport("path/to/CDLL", CallingConvention = CallingConvention.Cdecl)]
public static extern void test();
[DllImport("path/to/CDLL", CallingConvention = CallingConvention.Cdecl)]
public static extern void test2(int a);
[DllImport("path/to/CDLL", CallingConvention = CallingConvention.Cdecl)]
public static extern void test3(ref A a);
}
[StructLayout(LayoutKind.Sequential)]
struct A
{
[MarshalAs(UnmanagedType.I4)]
public int a, b;
}
}
No correct solution
OTHER TIPS
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow