[英]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中,右键单击您的项目,然后选择“参考”。
It is possible. 有可能的。 Google search would gave you answers.
Google搜索会给您答案。 Few links from Stackoverflow
来自Stackoverflow的链接很少
How to use c# Dll in vc++? 如何在vc ++中使用c#dll? using c# dll in project c++
在项目C ++中使用C#DLL
and you get many more links https://www.google.co.in/#sclient=psy-ab&hl=en&site=&source=hp&q=using+c%23+dll+in+vc%2B%2B&oq=using+C%23+dll+&gs_l=hp.3.2.0l4.1601.6409.0.9065.18.13.2.3.3.2.468.2716.0j9j1j2j1.13.0...0.0...1c.1.ixoWIPWicqo&pbx=1&bav=on.2,or.r_gc.r_pw.&fp=64f4e49ac7d1c408&biw=936&bih=595 您会获得更多链接https://www.google.co.in/#sclient=psy-ab&hl=zh-CN&site=&source=hp&q=using+c%23+dll+in+vc%2B%2B&oq=using+C %23 + DLL + gs_l = hp.3.2.0l4.1601.6409.0.9065.18.13.2.3.3.2.468.2716.0j9j1j2j1.13.0 ... 0.0 ... 1c.1.ixoWIPWicqo&PBX = 1&BAV = on.2,or.r_gc .r_pw。&FP = 64f4e49ac7d1c408&BIW = 936&波黑= 595
Hope this helps 希望这可以帮助
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.