Windows程序调用有什么区别?
我在另一个大陆的 Windows XP 计算机上有一个程序。 如果我通过双击关联文件来启动它,以便它根据文件类型关联运行程序,那么它会在某个时刻崩溃。 如果我通过将关联文件拖到程序图标来启动它,它就可以正常工作。 如果我双击该图标并将关联的文件拖到窗口中,它就可以正常工作。
现场人员向我保证,他已经对文件类型关联进行了三次检查,应该是正确的。
假设图标指向与注册表相同的可执行文件,那么以这两种不同的方式启动程序会有什么区别?
编辑:作为对评论的回应,我遇到问题的机器以日语运行,而我的普通机器是美国英语。
I have a program on a Windows XP computer on another continent. If I start it by double-clicking on an associated file, so that it runs the program according to the file-type association, it crashes at a certain point. If I start it by dragging an associated file to the program icon, it works fine. If I double-click on the icon and drag the associated file to the window, it works fine.
The guy on site assures me that he's triple-checked the file-type association, and it should be correct.
Assuming that the icon points to the same executable as the registry, what differences would there be in starting the program in these two different ways?
EDIT: In response to a comment, the machine I'm having problems on is running in Japanese, while my normal machine is US English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个可能的区别是初始工作目录:如果将文件拖到可执行文件上,则初始工作目录将设置为包含可执行文件的目录,而如果双击该文件,则初始工作目录将设置为某个独立的默认值文件或可执行文件所在的位置。
如果您想在所有情况下获得一致的行为,可以使用
SetCurrentDirectory()
将当前工作目录设置为您想要的任何目录; 我推荐包含可执行文件的目录,可以通过调用GetModuleFileName(NULL, ...)
并去掉可执行文件名称,或者通过检查main()
内的argv[0]
代码>.One possible difference is the initial working directory: if you drag a file onto the executable, the initial working directory is set to the directory containing the executable, whereas if you double click the file, the initial working directory is set to some default value independent of where the file or executable is located.
If you want to get consistent behavior in all cases, you can use
SetCurrentDirectory()
to set the current working directory to whatever you want; I recommend the directory containing the executable, which can be found by callingGetModuleFileName(NULL, ...)
and stripping off the executable name, or by examiningargv[0]
insidemain()
.当您双击该文件时,程序将运行,并且(通常)您双击的文件的名称将作为命令行参数传递给程序。
当您将其拖到窗口上时,程序已经在运行。
明显的区别在于程序的启动过程。 这个软件是自己写的吗? 也许检查它如何处理启动,并确保当命令行参数中有文件时仍然执行所有适当的代码路径。
如果您无法检查程序代码,或者它在启动时的行为方式,那么唯一要在注册表中检查并可能更改的就是文件名的传入方式。通常它们是在说话标记内传入的,因此文件的路径可以有空格并且不会混淆程序。 可以尝试的方法是确保协会在论点上使用谈话标记,或者如果已经这样做了,请尝试不使用。 也许程序没有正确处理说话标记。
When you double click the file, the program is run, and (usually) the name of the file that you double click, is passed in to the program as a command line argument.
When you are dragging onto the window, the program is already running.
The difference is obviously in the startup process that the program has. Is this software written in-house? Perhaps check how it handles starting up, and make sure that all appropriate code paths are still executed when there is a file in the command line arguments.
If you can't check the program code, or how it behaves at startup, about the only thing to check in the registry, and possibly change, is how the filename is passed in. Usually they are passed in inside talking marks, so that the path to the file can have spaces and not confuse the program. Something to try would be to make sure the association uses talking marks on the argument, or if it already does, try it without. Perhaps the program isn't handling the talking marks correctly.