导入c++;DLL到c#

导入c++;DLL到c#,c#,c++,dll,C#,C++,Dll,请帮我拿c#中的DLLImpot。 我有DLL,用DLL导出查看器分析,该类方法如下所示: public: static float * __cdecl Evaluator::calculateLM(float *,float *,int,int,float *,float *) 我就是搞不懂如何把它导入c语言中。终于弄明白了 [DllImport("LMModelSolve.dll", EntryPoint = "?calculateLM@Evaluator@@SAP

请帮我拿c#中的DLLImpot。 我有DLL,用DLL导出查看器分析,该类方法如下所示:

public: static float * __cdecl Evaluator::calculateLM(float *,float *,int,int,float *,float *)

我就是搞不懂如何把它导入c语言中。

终于弄明白了

[DllImport("LMModelSolve.dll",
            EntryPoint = "?calculateLM@Evaluator@@SAPAMPAM0HH00@Z",
            CallingConvention = CallingConvention.Cdecl)
        ]
        static extern IntPtr calculateLM(float[] x, float[] y, int n, int iterations, float[] lower, float[] upper);
要调用并获得结果:

IntPtr res = calculateLM(x, y, ndata, 200, lower, upper);
            float[] resultVertices = new float[4];
            Marshal.Copy(res,resultVertices,0,4);

请参阅,这通常是内存泄漏,因为无法释放返回的阵列。你最好测试一下,千万次。