Can you run C# Code from c++?
Can you run C# code from c+开发者_如何学JAVA+? and How?
If you're C++ code is "managed" C++ that's built on the .NET common language run-time (CLR), then it's easy to reference a C# assembly and invoke public classes and methods. If, however, your C++ code is "native" (not built on the CLR), then you'll want to register your C# assembly for COM interop and invoke the COM object from your C++ code. There's an MSDN article that covers all the gory details:
http://msdn.microsoft.com/en-us/library/w29wacsy(VS.80).aspx
There's also a good article on CodeProject by Nick Parker called "Exposing .NET Components to COM" that you may find useful.
You can use unmanaged C++ to run a .NET application, but how difficult it will be will depend on which version of .NET you are using.
When I did this with .NET 2.0 it took me two solid weeks to get it working.
The answer in this page gives guidance as to which programs are needed to do this.
http://www.pcreview.co.uk/forums/thread-1225474.php
The other option that you have, depending on what you're trying to do, is to host the CLR in your application which allows you to more tightly integrate the C# code than is possible by going through COM. You can read an overview of doing this in this MSDN Magazine article.
With C++/CLI, yes (formerly Managed C++ -- which had different extensions to the language).
yes, you can use COM to call .NET
You can call .NET code without COM by using the mscoree.dll ClrCreateManagedInstance Function. You need to supply the assembly qualified name of the type name you want to create, in the pTypeName parameter.
From memory, in some cases you may need to add the ComVisible attribute to the interfaces or classes you wish to access using ClrCreateManagedInstance(). However this does not require you to also register your class or any of the other messy deployment issues that go with COM.
I'm guessing the answer that would really be useful to Chad is:
Yes, it is most definitely technically possible to run C# code from C++. However, if the other answers on this page sound like they are going over your head, then you are nowhere near experienced enough to actually do this. It is pretty difficult to pull off, all things considered, so unless you really need to be running C# code from C++, it might be best to just rewrite the C# code as C++.
精彩评论