Answers for "how to import a c++ struct to c# from lib"

C#
0

how to import a c++ struct to c# from lib

[StructLayout(LayoutKind.Sequential)]
public struct ExampleStruct
{
    public int PropertyOne;
 
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10 )]
    public int[] AnotherProperty;
}
 
[DllImport("exampleLibrary.dll", EntryPoint="FunctionOne")]  
public static extern int FunctionOne(int a, int b);
 
[DllImport("exampleLibrary.dll", EntryPoint="FunctionTwo")]  
public static extern void FunctionTwo(ref ExampleStruct str);
 
[DllImport("exampleLibrary.dll", EntryPoint="FunctionThree")]  
public static extern void FunctionThree(ref int ptr);
 
[DllImport("exampleLibrary.dll", EntryPoint="FunctionFour")]  
public static extern void FunctionFour([MarshalAs(UnmanagedType.LPArray)]int[] buffer, int buffer_size);
Posted by: Guest on April-10-2021

C# Answers by Framework

Browse Popular Code Answers by Language