C#怎样调用c编写的dll,dll中函数为 extern "C" void PASCAL EXPORT relation(int len,double *ch1,double *ch2,double *data);
ch1 ch2 data 都是数组
那么在c#中该写怎样一个函数?
各位高手快帮忙啊

解决方案 »

  1.   


    using System.Runtime.InteropServices;        
    [DllImport("xxx.dll")]
    static extern void relation(int len, double[] ch1, double[] ch2, double[] data); 
      

  2.   

    直接在项目里载入DLL文件怎么样?
      

  3.   

    如果是非托管的,就用DllImport,举例 
      using System; 
      using System.Runtime.InteropServices; 
      class MainApp 
          [DllImport("Kernel32")]                    //读取动态库文件 
            public static extern int GetProcAddress(int handle, String funcname);   给你讲一下我的经验: 
      首先 你在C#中调用的 是C++ 写的一个动态库。比如Kernel32.dll 中的 函数; 
      这个函数用C++写 有如下要求: 
    1、 必须为全局函数 
    2、 函数参数 必须为基本类型,也就是C++ 和C#都有的类型,否则你在public static extern int GetProcAddress(int handle, String funcname); 
        这里没有办法声明。 其余的 没什么了; 还有你可以参考这里:http://blog.csdn.net/jingshuaizh/archive/2009/02/04/3862019.aspx
      

  4.   

    1.把你编译好dll文件放到C#程序的bin/debug/文件夹下。
    2.[DllImport("yourdllname.dll")]
    public static extern void relation(int len,ref double ch1,ref double ch2,ref double data);
    或者像一楼说的那样
    public static extern void relation(int len, double[] ch1, double[] ch2, double[] data); 
    我没有试,你试一下。
    3.然后就可以用了。