我有以下问题:
我有两个项目,Project Game包含一个使用SDL库以C ++编码的游戏。Project Launcher是一个C#.NET项目,它提供了一个界面,可在启动Project Game之前从中选择选项。
我的问题是:A)如何从Project Launcher中启动Project Game?B)如何将参数从Project Launcher传递到Project Game?
我还没有真正找到明确的解决方案,只是在这里和那里窃窃私语。对于参数来说,很明显,只需使用参数调用.exe并在C ++中读取它们,但我想知道是否存在一种更清晰的方法来将其内置于.NET中。任何帮助将不胜感激。如果找到解决方案,请在此处发布。
.NET框架包括一个名为Process的类,它包含在Diagnostics名称空间中。您应该使用System.Diagnostics包含该名称空间,然后像下面这样启动应用程序:
using System.Diagnostics;
// Prepare the process to run
ProcessStartInfo start = new ProcessStartInfo();
// Enter in the command line arguments, everything you would enter after the executable name itself
start.Arguments = "readme.txt";
// Enter the executable to run, including the complete path
start.FileName = "notepad";
// Do you want to show a console window?
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;
//Is it maximized?
start.WindowStyle = ProcessWindowStyle.Maximized;
// Run the external process & wait for it to finish
using (Process proc = Process.Start(start))
{
proc.WaitForExit();
// Retrieve the app's exit code
exitCode = proc.ExitCode;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句