代码如下:但总是提示:方法类型签名与PIvoke不兼容 这里 返回值mydb是一个结构体,输入参数为数组指针: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices;//引入dll文件的函数 namespace dll文件链接 { class Program { [DllImport("EMatrix.dll", EntryPoint = "EnergySolver", CallingConvention = CallingConvention.Cdecl)] private static extern mydb EnergySolver(IntPtr ZUCHNEG);//引入dll中写好的函数 [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct mydb { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)] public double[] x;//Y坐标的值,单位U(mm/s),该数组从1开始计数 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public double [] y;//X坐标的值,单位P(MPa),该数组从1开始计数 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20*4)] public double[]a;//X坐标的值,单位P(MPa),该数组从1开始计数 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)] public double[] b;//X坐标的值,单位P(MPa),该数组从1开始计数 } static void Main(string[] args) { double[] m_PeiFang1 = new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; m_PeiFang1[0] = 13.731882598335664; m_PeiFang1[1] = 89.175685804764413; m_PeiFang1[2] = 13.731882598335664; m_PeiFang1[3] = 2.2614300711402282; m_PeiFang1[4] = -3438.4000000000001; m_PeiFang1[5] = 450.00000000000000; IntPtr ptr = Marshal.AllocHGlobal(m_PeiFang1.Length * Marshal.SizeOf(typeof(double)));//分配内存 mydb a = EnergySolver( ptr); Console.ReadKey(); } } } |
欢迎光临 FineUI 官方论坛 (https://fineui.com/bbs/) | Powered by Discuz! X3.4 |