C#调用C++编译的dll文件 (持续更新)

来源:互联网 发布:java游戏nba2010中文 编辑:程序博客网 时间:2024/05/16 08:25

一    简单调用的实现

       C++ 编译的dll描述:
                     文 件 名:test.dll
                     函数原型:int OptionAdd(int a,int b)
       C#调用实现:
                    1、引用命名空间      System.Runtime.InteropServices
                    2、载入dll文件         [DLLImport("test.dll")]
                    3、声明原型              public static extern int OptionAdd(int a, int b)

二  参数中包含指向结构体的指针

       C++ 编译的dll描述:
                    文 件 名:test.dll
                    函数原型:int OptionAdd(Point* a,Point* b)


      结构体为: 
       public struct Point
       {
              public int x;
              public int y;
              public int z;
       }
      C#调用实现:
                  1、引用命名空间 System.Runtime.InteropServices
                  2、载入dll文件  [DLLImport("test.dll")]
                  3、声明原型
                                 a)   public static extern int OptionAdd(ref Point a, ref Point b)
                                 b)   public static extern int OptionAdd(Point[] a, Point[] b)
                    注意:a方法  可以使用绝大多数的情况,不影响运算;
                                b方法  可以传入null,而a则不允许




(持续更新)

0 0
原创粉丝点击