UNITY3D C#調用C封裝的函數庫方法
2023/10/30??????點擊:
如果在C函數庫test.dll中存在函數int test1(int a, int b), 那么C#對動態庫函數的引用可以這樣聲明,之后可以調用test1函數.
[DllImport("test", EntryPoint = "test1", CallingConvention = CallingConvention.Cdecl)] public static extern int test1(int a, int b);那么如果函數是指針參數怎么辦?
若dll中存在函數int test2(int *a, int *b), 那么C#對動態庫函數的引用可以這樣聲明,之后可以調用test2函數.
[DllImport("test", EntryPoint = "test1", CallingConvention = CallingConvention.Cdecl)] public static extern int test1(ref int a,ref int b);如遇到函數的參數為結構體又該如何呢?
struct mydatapack { string name; string sex; int age; } int test3(struct mydatapack data);
我們可以這樣聲明:
[StructLayout(LayoutKind.Sequential)] public struct datapaclk { public string name; public string sex; public string age; public datapack(string Name,string Sex, int age) { this.name= Name; this.sex= Sex; this.age = Age; } } [DllImport("test", EntryPoint = "test3", CallingConvention = CallingConvention.Cdecl)] public static extern int test3(datapack data);
- 上一篇:協作機械臂遙操作數據手套研制成功 2024/1/27
- 下一篇:unity3d C# 調用C程序封裝結構體函數 2023/10/30