返回一个值给外部调用者 C++
我正在从 C# 调用 C/C++ 程序 (exe),我想从 C/C++ 返回一个浮点值到 C# 代码,我有为单个值写入文件 a 的 exe 代码,而不是我想返回将该值传递给 C#。我怎样才能做到这一点?
I am invoking a C/C++ program (exe) from C#, I want to return a float value from my C/C++ to the C# code, I have the exe code which writes file a for a single value, instead I want to return that value to C#. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果该代码将浮点数写入文件,那么您所能做的就是随后读取该文件。
If that code writes a float to a file, then all you can do is read the file afterwards.
您可以将 C/C++ 程序的结果输出到标准输出,然后在调用后用 C# 解析它。
检查这个答案:调用外部程序的最佳方式 。
或者,如果您的程序被多次调用,也许更好的解决方案是让它运行并通过本地套接字与您的 C# 程序通信 C#程序可以通过网络发送请求并返回结果。
You could output the result of your C/C++ program to the standard output, and then parse it with C# after the invokation.
Check this answer: Best Way to call external program in c# and parse output
Or if your program is called a lot a time, maybe a better solution would be to let it run and communicate with your C# program through local sockets. C# program may send request by network and get the result back.