问题描述
我想一个VC DLL引用添加到我的C#Visual Studio项目。但是,当我尝试添加它,我明白了,这不是一个有效的程序集或COM组件。
I want to add a VC++ DLL reference into my C# Visual Studio project. But when I try to add it I see, "It is not a valid assembly or COM component".
请建议我如何利用VC ++ DLL作为参考。一个C#项目
Please suggest how I can use the VC++ DLL as a reference in a C# project.
推荐答案
有使用从C#一个C ++ DLL两种选择:要么COM互操作,或P / Invoke的。 COM互操作涉及您的C ++ DLL创建一个COM对象,然后将其作为参考。您可以在这一点上使用像一个C#对象COM对象(在大多数情况下)。
There are two options for using a C++ DLL from C#: either COM interop, or P/Invoke. COM Interop involves creating a COM object in your C++ DLL, and then adding it as a reference. You can use the COM object like a C# object (for the most part) at this point.
P /调用允许你调用导出的函数从C#(想想调用标准从C#Win32 API函数)。这可能是更容易建立,因为所有你需要做的是出口的函数,但是可能导致你重构你的代码在C ++ DLL,因为它不是一个做事的非常面向对象的方法。
P/Invoke allows you to call exported functions from C# (think calling standard Win32 API functions from C#). This is likely easier to set up, since all you need to do is export a function, however that could cause you to refactor your code in the C++ DLL, since it's not a very OOP way of doing things.
这篇关于我如何添加一个VC DLL。在我的C#的Visual Studio项目的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!