如何从exe或DLL获取返回值到另一个应用程序 [英] How do I get the return value from exe or DLL into another application
本文介绍了如何从exe或DLL获取返回值到另一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个WPF表单,它有一个按钮和一个文本框,当我点击它需要打开一个winform exe,它有一个列表框,列表框中选中的项目应该返回到WPF Form文本框,< br $> b $ b
我尝试过:
WPF按钮代码
I have a WPF form which has a button and a textbox, when i click the button it needs to open a winform exe which has a list box, the items selected in the listbox should be returned to the WPF Form textbox,
What I have tried:
WPF BUTTON CODE
System.Diagnostics.ProcessStartInfo p = new System.Diagnostics.ProcessStartInfo();
//System.Diagnostics.Process p = new System.Diagnostics.Process();
p.UseShellExecute = false;
p.RedirectStandardOutput = true;
p.FileName= System.IO.Path.GetDirectoryName(GeneralActivities.ExecutionPath) + "\\MYTESTAPP.exe";
try
{
using (System.Diagnostics.Process startprocess = System.Diagnostics.Process.Start(p))
{
startprocess.WaitForExit();
string output = startprocess.StandardOutput.ReadToEnd();
MessageBox.Show(output);
}
}
推荐答案
这样的事情:
Something like this:
using (System.Diagnostics.Process p = new System.Diagnostics.Process())
{
p.StartInfo = new System.Diagnostics.ProcessStartInfo(System.IO.Path.GetDirectoryName(GeneralActivities.ExecutionPath) + "\\MYTESTAPP.exe");
p.StartInfo.CreateNoWindow = true;
p.StartInfo.ErrorDialog = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.Start();
System.Threading.Thread.Sleep(10000); // for testing ...
if (!p.HasExited)
{
p.WaitForExit(120000); // wait 2 minutes to finish
if (!p.HasExited)
{
p.Kill();
}
}
string output = p.StandardOutput.ReadToEnd();
}
这篇关于如何从exe或DLL获取返回值到另一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文