In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to call C # by C++/CLI". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to call C # by C++/CLI".
Surmount the language barrier: C++/CLI calls C#
When a C # project needs to refer to C++dll, you can use DLLIMPORT directly to make the call. In reverse, C++ projects cannot simply rely on references to use C#DLL. Because the default configuration of the C++ project is not supported by the common language runtime. So we need to change some configuration to make the call to C # dll. First encapsulate the dll of C# with managed C++ (CLI), and then call the encapsulated dll by unmanaged C++. The key steps for c++/cli to call c#dll are as follows:
[thank you for adding: this sample is only used for developer research. C++ clr will conflict with some C++ compilation options, and some mfc external link sources are not supported. ]
First of all, we completed the development of C # dll:
Namespace Csharp {public class Class1 {public string Name = string.Empty; public Class1 () {Name = "We can use clients!";}
You can get the dll of Csharp by compiling.
Secondly, the configuration of C++ project properties: add common language runtime support / clr (c++/cli)
In the next step, add a new reference and select the Csharp.dll compiled in our * * step.
# using and using namespace are needed in the code to make the call to dll. Be careful to use gcnew when allocating memory, and you need gc to allocate memory to it. Managed objects need to be declared using ^.
# include "stdafx.h" # using "Csharp.dll" using namespace Csharp; int _ tmain (int argc, _ TCHAR* argv []) {Class1 ^ a = gcnew Class1 (); printf ("% Spartan", a-> Name); return 0;}
The results are as follows:
This enables C++/CLI to call C#dll.
At this point, unmanaged C++ code in other projects can call the c++dll to make calls to the managed c#dll, which plays the role of wrapper.
Thank you for your reading, the above is the content of "how to call C++/CLI C #", after the study of this article, I believe you have a deeper understanding of how to call C # C++/CLI, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.