簡體   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