奇怪的是,fopen 和 fopen_s 返回 null
我的编码环境:编译器是Microsoft Visual Studio C++ 2008。
好的,顺便说一下,我有两个文件,a.exe和b.exe。它们都是Win32控制台应用程序。我想做的是,当我打开 b.exe 并按下那里的按钮时,它将执行 a.exe。
但奇怪的是,当我这样做时,a.exe 没有按应有的方式运行。它遇到一个错误,该错误的原因是:当 a.exe 尝试打开 x.dat 文件时,fopen 返回了 NULL 值。我尝试用 fopen_s 更改 fopen,但也没有成功。
奇怪的是:当我双击执行 a.exe 时,它运行得很好。但是当我用 b.exe 调用 a.exe 时,fopen 和 fopen_s 函数无法正常工作。我还尝试使用 Java 文件调用 a.exe,得到相同的结果。
我可以做些什么来解决这个问题吗?
My coding environment: the compiler is Microsoft Visual Studio C++ 2008.
Okay, I have two files by the way, say, a.exe and b.exe. Both of them are Win32 console application. What I'm trying to do is, when I open b.exe and press a button there, it'll execute a.exe.
But strangely, when I do that, a.exe didn't run as it should be. It encounters an error which is caused by: when a.exe tried to fopen a x.dat file, fopen returned a NULL value. I've tried to change that fopen with fopen_s, but I didn't succeed either.
The strange thing is that: when I execute a.exe by double-clicking it, it runs PERFECTLY. But when I invoke a.exe with b.exe, the fopen and fopen_s functions didn't work as it should be. And I've also tried invoke a.exe with a Java file, with the same result.
Is there anything that I could do to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保当您运行从 b.exe 调用的 a.exe 时,您使用的是正确的工作目录,或者您提供给 fopen 的文件路径具有完整路径。
Make sure when you run a.exe invoking from b.exe that you are using the correct working directory or that the file path that you provide to fopen has a full path.