繁体   English   中英

如何在我的 C# Visual Studio 项目中添加 VC++ DLL 作为参考?

[英]How can I add a VC++ DLL as a reference in my C# Visual Studio project?

我想将 VC++ DLL 引用添加到我的 C# Visual Studio 项目中。 但是当我尝试添加它时,我看到“它不是有效的程序集或 COM 组件”。

请建议我如何在 C# 项目中使用 VC++ DLL 作为参考。

您只能在 C# 中的 C++ 组件已准备好使用时使用,例如通过使用 C++/CLI 编写或编写为 COM 服务器。

如果您的组件是普通的 C++ dll 您需要编写一些包装代码,最好是 C++/Cli

使用 C# 中的 C++ DLL 有两个选项:ZD47C174ED277BDF06CFC72763AB7Inop7Internoke COM Interop involves creating a COM object in your C++ DLL, and then adding it as a reference. 您可以像 C# object 一样使用 COM object (对于大多数情况)。

P/Invoke 允许您从 C# 调用导出的函数(想想从 C# 调用标准 Win32 API 函数)。 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.

我不确定这是否解决..

跑:

tlbimp /out:MyOldCom.dll MyNewAssembly.tlb

然后像使用任何其他程序集一样使用它。

请参考

http://msdn.microsoft.com/en-us/library/aa302324.aspx

http://msdn.microsoft.com/en-us/magazine/cc301501.aspx

IE)

一种方法是将 package 您的 DLL 作为 COM ZA2F2ED4F8E88D03A67F6B7D8Z DLL 使用另一种方法是 ZA2F2ED4F8EBC2CBB4C21A29DC40AB6

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM