如何避免被调用的exe立即崩溃 [英] How to avoide the called exe is clossing immediatly

查看:87
本文介绍了如何避免被调用的exe立即崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的wpf c#应用程序中,我正在调用一个c ++ exe文件,它正在调用但它会自动关闭。



ProcessStartInfo s = new ProcessStartInfo();

s.WindowStyle = ProcessWindowStyle.Hidden;

s.FileName = example.exe;

System.Diagnostics.Process.Start(s);



错误名称:example.exe已停止工作



我尝试过:



我从c#应用程序调用了一个c ++ exe文件,但它自动关闭

In my wpf c# application i am calling one c++ exe file, It is calling but it is closing automatically.

ProcessStartInfo s = new ProcessStartInfo();
s.WindowStyle = ProcessWindowStyle.Hidden;
s.FileName = example.exe;
System.Diagnostics.Process.Start(s);

Error name:example.exe has stopped working

What I have tried:

I called one c++ exe file from my c# application but it is closing automatically

推荐答案

在托管exe中调用Unmanaged exe是否存在任何问题

否 - 当您使用Process.Start启动应用程序时,它是一个完全独立的应用程序,它与启动它的应用程序。它可以是任何内容,包括导致Windows打开关联程序(如Web浏览器)的文件。 Managaed / unmanaged是无关紧要的。



但是......您显示的代码将无法编译,因为您设置的FileName不是字符串。

假设你的意思是:

"Is there any issues in calling Unmanaged exe in managed exe"
No - when you start an application with Process.Start it's a completely independant app which shares nothing with the app that started it. It can be anything, including a file that causes Windows to open the associated program such as a web browser. Managaed / unmanaged is irrelevant.

But...The code you show won't compile as the FileName you set isn't a string.
Assuming you mean:
s.FileName = "example.exe";

相反,最可能的原因是Windows无法找到您指定的文件。如果它不在当前目录中,或在Windows应用程序文件夹中,或在Windows路径上,那么它会赢;但是可能会找到并且这可能会导致您的问题。

我建议尝试给出EXE文件的绝对引用:

instead, then the most likely reason is that Windows can't find the file you specified. If it isn't in the current directory, or in a Windows application folder, or on the Windows Path then it won;t be found and that might cause your problem.
I'd suggest trying by giving an absolute reference to the EXE file:

s.FileName = @"C:\Program Files\My Examples\example.exe";

并查看是否修复了它。

或者,如果通过仍然立即关闭找到文件,则可能是它需要一些您不提供的参数 - 所以首先通过命令提示符执行应用程序:按住Windows键并按R,然后键入CMD并按ENTER键。输入应用名称,看看会发生什么。可能您会收到找不到文件错误,因此请使用CD转到正确的文件夹,然后重试。

And see if that fixes it.
Alternatively, if the file is being found by still shuts down immediately, it's probably that it needs some parameters you aren't supplying - so start by executing the app via a command prompt: Hold the Windows Key and press "R", then type CMD and press ENTER. Type the app name and see what happens. Probably, you'll get a "File not found" error, so use CD to get to the right folder, and try again.


这篇关于如何避免被调用的exe立即崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆