问题
I'm using Visual Studio 2010. I've written a dll in C#, managed dll then. Now for some reason, I need to write a software in C++ (.NET then also managed). I need to import the C# dll into my C++ .NET code. 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? Thanks,
回答1:
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. 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.
回答2:
You need to add a reference into your project. In Visual Studio, right-click your project, then select "References".
回答3:
It is possible. Google search would gave you answers. Few links from Stackoverflow
How to use c# Dll in vc++? using c# dll in project c++
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
Hope this helps
回答4:
You add reference to you assembly, Set ComVisible attribute
to your assembly
Edit your AssemblyInfo.cs
[assembly: ComVisible(true)]
.Net Framework have MSIL langage in order to manage interoperability betwwen different langages
Link : http://support.microsoft.com/kb/828736
回答5:
You just need to add only reference of that dll in your project, as George has replied. then use that namespace or name of classes in your code...
来源:https://stackoverflow.com/questions/12387772/importing-c-sharp-dll-to-c-managed-code-net