Import c++ DLL to c#

本文关键字:to DLL c++ Import | 更新日期: 2023-09-27 17:57:00

请帮助我在c#中使用DLLImpot。我有DLL,用DLL导出查看器对其进行了分析,显示了此类方法:

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

我只是不知道如何将其DllImport到 c# 中。

Import c++ DLL to 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);