如何在C#包装器中调用C ++非托管代码?

时间:2019-07-02 06:48:17

标签: c# c++

我有一个C#包装器项目,该项目在[DllImport]属性和静态外部方法的帮助下使用C ++非托管dll代码。这是MSDN描述的首选方法。

问题是我们只能拥有一个c ++运行器,这意味着我们不能并行运行任务。

如何在不使用dllimport + static extern方法的情况下调用非托管C ++,以便当我们实例化一个c#对象时,它实例化一个新的c ++ dll对象

这就是我们现在调用C ++代码的方式。

public class FMU : IDisposable
    {

        [DllImport("FMU.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        private static extern IntPtr Load(string fmuFileName, bool isCoSimulation, AddMessageDelegate messageDelegate, int arrayLocation);

        [DllImport("FMU.dll", CallingConvention = CallingConvention.Cdecl)]
        private static extern IntPtr Instantiate(IntPtr fmu, bool isCoSimulation, bool loggingOn, int nCategories, string[] categories);

        [DllImport("kernel32", SetLastError = true)]
        private static extern bool FreeLibrary(IntPtr hModule);

0 个答案:

没有答案
相关问题