从C#/ WPF调用C ++程序

时间:2011-03-03 13:31:43

标签: c# c++ wpf

有人能指出我如何从C#运行已编译的C ++程序(可执行文件)的完整示例。

提前致谢。

1 个答案:

答案 0 :(得分:1)

我认为你想要的是这样的:

Process myProcess = new Process();

try
{
    myProcess.StartInfo.UseShellExecute = false;
    // You can start any process; HelloWorld is a do-nothing example.
    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
    myProcess.StartInfo.CreateNoWindow = true;
    myProcess.Start();
    // This code assumes the process you are starting will terminate itself. 
    // Given that is is started without a window so you cannot terminate it 
    // on the desktop, it must terminate itself or you can do it programmatically
    // from this application using the Kill method.
}
catch (Exception e)
{
    Console.WriteLine(e.Message);
}