In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the "pit analysis of C# calling C++". In daily operation, I believe many people have doubts about the pit analysis of C# calling C++. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "C# calling C++ pit analysis"! Next, please follow the editor to study!
Generally speaking, C# calls the dll produced by C++, as follows:
C++ 's project should be set to "Export dll's project", and the exported function is generally:
Extern "C" _ declspec (dllexport) int Convrnx (int format, rnxopt_t opt, char * file, char * * ofile) {....}
After you get a dll of C++, put it in the generation directory of C #, that is, with .exe.
On the other hand, Che needs to:
[DllImport ("RtklibHelper.dll", EntryPoint = "Convrnx", CallingConvention = CallingConvention.Cdecl)] public static extern int Convrnx (int format, rnxopt_t opt, string file, string [] ofile) {....}
Pit one: how does the type of C# correspond to the type of C++ (for example: string corresponds to * char,string [] corresponds to char**)
Solution 1: there is a magical tool called CLRInsideOut, the handwriting of Microsoft:
For example, the structure rnxopt_t in C++, in which the nested structure snrmask_t, etc., only needs to be sorted out from top to bottom with txt (C++ 's statement is very fastidious before and after), and the C # code is directly on the right.
Pit 2: everything is fine when calling C++ in native C#. If you put it on another machine, you can't find the specified module. (the exception came from HRESULT:0x8007007E), and various search attempts failed (including trying to install the Vs C++ environment).
Programmer's intuition: it must be the dll produced by C++, which calls the dll of the system, but not necessarily on other computers.
Idea: find out what this dll calls
Solution 2: using Microsoft tools again:
Got it. These are the dll.
Programmer's intuition: this thing, absolutely under c:\ window, search and find: WINMM.dll is in both folders, which one is it?
Answer: you just need to search another computer, and if you lack it, copy that.
Find them all:
Then put it in the same directory as exe; (according to the custom of C++ dll, dynamic libraries are always found in the current directory and system directory, so there is no need to put them in the corresponding folders on the target computer one by one.)
At this point, the study of "pit analysis of C# calling C++" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.