Pim*_*ger 3 c c# communication
什么是C和C#进程之间通信的最佳方式.我需要从C#进程发送包含命令和参数等的消息.到C过程.然后C过程必须能够发送回复.
我在C#进程中启动了C进程.
实现这一目标的最佳方法是什么?我尝试使用stdin和stdout,但这不能很好地工作(由于某种原因,C进程的stdin被一些字符串(x(U + 266C)Q)发送垃圾邮件(U + 266C是一个UTF8传送十六个音符)
你真的需要单独的流程吗?如果您拥有这两个代码,为什么不通过导入c库方法进行互操作调用:
class Program
{
[DllImport("yourlibrary.dll")]
public static extern int YourMethod(int parameter);
static void Main(string[] args)
{
Console.WriteLine(YourMethod(42));
}
}
Run Code Online (Sandbox Code Playgroud)
并在您的C库中使用.def文件导出您的方法:
LIBRARY "yourlibrary"
EXPORTS
YourMethod
Run Code Online (Sandbox Code Playgroud)