简体   繁体   English

将C#dll导入C ++托管代码(.NET)

[英]Importing C# dll to C++ managed code (.NET)

I'm using Visual Studio 2010. I've written a dll in C#, managed dll then. 我使用的是Visual Studio2010。我已经用C#编写了一个dll,然后是托管dll。 Now for some reason, I need to write a software in C++ (.NET then also managed). 现在由于某种原因,我需要用C ++编写一个软件(.NET也要进行管理)。 I need to import the C# dll into my C++ .NET code. 我需要将C#dll导入我的C ++ .NET代码。 I can't figure out to do this, I've made several search but this problem seems to not be covered. 我不知道要这样做,我进行了几次搜索,但似乎没有解决这个问题。 For example, in C# I don't have include file, then how my C++ (.NET) projet knows about classes and functions inside the dll? 例如,在C#中我没有包含文件,那么我的C ++(.NET)项目如何知道dll中的类和函数? Thanks, 谢谢,

In Visual Studio, bring up the properties of the C++/CLI project, go to "Common Properties/Framework and References" in the tree at the left, and click the "Add New Reference" button. 在Visual Studio中,调出C ++ / CLI项目的属性,转到左侧树中的“公共属性/框架和引用”,然后单击“添加新引用”按钮。 This will bring up the standard "Add Reference" dialog you can get from a C# project, just select your C# DLL or reference a C# project in the same solution. 这将打开标准的“添加引用”对话框,您可以从C#项目中获得该对话框,只需选择C#DLL或在同一解决方案中引用C#项目即可。

You need to add a reference into your project. 您需要在项目中添加参考。 In Visual Studio, right-click your project, then select "References". 在Visual Studio中,右键单击您的项目,然后选择“参考”。

You add reference to you assembly, Set ComVisible attribute to your assembly 您添加对程序集的引用,将ComVisible attribute设置为您的程序集

Edit your AssemblyInfo.cs 编辑您的AssemblyInfo.cs

[assembly: ComVisible(true)]

.Net Framework have MSIL langage in order to manage interoperability betwwen different langages .Net Framework具有MSIL语言,以便管理不同语言之间的互操作性

Link : http://support.microsoft.com/kb/828736 链接: http//support.microsoft.com/kb/828736

You just need to add only reference of that dll in your project, as George has replied. 正如George回答的那样,您只需要在项目中添加该dll的引用即可。 then use that namespace or name of classes in your code... 然后在您的代码中使用该名称空间或类的名称...

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

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