将c ++ DLL导入c#

时间:2013-01-31 09:41:17

标签: c# c++ dll

请帮我解决c#中的DLLImpot。 我有DLL,用DLL Export Viewer分析它,这个类方法显示:

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

我无法弄清楚如何将DllImport变成c#。

1 个答案:

答案 0 :(得分:0)

终于明白了。

[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);