如何在 C 和 C# 应用程序之间进行通信
C 和 C# 进程之间通信的最佳方式是什么?我需要从 C# 进程发送包含命令和参数等的消息。到C进程。然后 C 进程必须能够发送回复。
我在C#进程中启动C进程。
实现这一目标的最佳方法是什么?我尝试使用标准输入和标准输出,但这效果不佳(由于某种原因,C 进程的标准输入被一些字符串 (x(U+266C)Q) 垃圾邮件(U+266C 是 UTF8 光束十六音符)
What would be the best way to communicate between a C and a C# process. I need to send messages containing commands and params and such from the C# process. to the C process. and the C process then has to be able to send reply's.
I start the C process in the C# process.
What would be the best way to achieve this? I tried using stdin and stdout but this doesn't work well (for some reason the stdin of the C process is spammed with some string (x(U+266C)Q) (U+266C is a UTF8 beamed sixteen note)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您真的需要单独的流程吗?如果您拥有这两个代码,为什么不通过导入 C 库方法来进行互操作调用:
并在 C 库中使用 .def 文件导出方法:
Do you really need as separate processes? If you own both codes why don't you make interop calls by importing the c library methods:
and in your C library you export your method using a .def file:
听起来您无权访问 C 程序源代码。我将使用 ProcessStartInfo 启动您的外部 C 程序。但在此之前,您需要重定向输入/输出。请参阅下面的示例代码:
It sound like you dont have access to the C program source code. I would use ProcessStartInfo to launch your extern C program. But before you do, you redirect the Input/Output. See sample code below:
您的流程是否需要并行运行,或者您启动一个外部流程并需要获取其结果?如果您只是启动一个子进程,那么,正如评论中所述,您不会对传递给子应用程序的数据执行 UTF16->ASCII 转换。
如果您需要并行运行进程并在它们之间交换消息,请查看我们的 MsgConnect 产品,这是专门为此类任务设计的。
Do your processes need to run in parallel or you start an external process and need to obtain it's results? If you just start a child process, then, as said in the comment, you don't perform UTF16->ASCII conversion of data being passed to the child application.
If you need to run processes in parallel and exchange messages between them, take a look at our MsgConnect product, which was designed specifically for such tasks.