更新时间:2023-02-09 15:16:11
我更喜欢用C ++/CLI(以前称为Managed C ++)编写托管包装,因为这样可以更轻松地显式地执行托管/非托管所需的操作C ++方面的互操作性,并且您的C#不会受到P/Invoke样式代码的污染.
I prefer to write a managed wrapper in C++/CLI (formerly Managed C++), as it makes it much easier to explicitly do what you want with managed/unmanaged interoperability on the C++ side, and your C# doesn't get polluted with P/Invoke style code.
编辑刚刚注意到您的评论"但是我要从C#调用此函数,并且不相信我可以导出Class,而只能导出函数或变量."
Edit Just noticed your comment "However I'm going to be calling this function from C# and don't believe I can export a Class, just functions or variables."
那不是完全正确-C#可以从C ++/CLI代码生成的程序集中导入完整的类.
That's not entirely true - C# can import full classes from an assembly generated from C++/CLI code.