将C ++代码导出为DLL并使用C#导入? [英] Exporting C++ code as a DLL and import using C#?
问题描述
我是C ++的新手(已经是一个python程序员),所以我想知道 - 我需要遵循的步骤才能将其导出为DLL这可以从C#程序导入?任何建议?
如果您希望C ++类在C#应用程序中可用,您将需要使用COM或目标您的C ++程序中的CLR(即使用C ++ / CLI)。
如果您只需要C ++ DLL中的某些功能,您可以从C#中调用POD类型参数然后将每个函数声明为 externC
以避免名称变形,并使用 DLLImport
属性导入该函数。 PInvoke.net 是一个很棒的资源。
I have a program written in C++ with a main function that calls a bunch of other C++ classes/functions.
I am new to C++ (been a python programmer), so I'm wondering - What are the steps I need to follow to be able to export this as a DLL that is importable from a C# program? Any suggestions?
If you want your C++ classes to be usable in a C# application you will need to use COM or target the CLR in your C++ program (i.e., use C++/CLI).
If you simply have some functions in the C++ DLL that you want to call from C# that take POD type arguments then declare each function as extern "C"
to avoid name mangling and use the DLLImport
attribute to import the function. PInvoke.net is a great resource here.
这篇关于将C ++代码导出为DLL并使用C#导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!