为什么在“%1 不是有效的 Win32 应用程序"中很少替换 %1. [英] Why is %1 rarely substituted in "%1 is not a valid Win32 application."

查看:19
本文介绍了为什么在“%1 不是有效的 Win32 应用程序"中很少替换 %1.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信大多数 Windows 开发人员都熟悉此错误消息,通常是在尝试混合 32 位和 64 位可执行文件时.尤其是 Python 和 Java 都能搞定.

I'm sure most Windows developers are familiar with this error message, usually when trying to mix 32- and 64-bit executables. In particular Python and Java can both get it.

%1 无效Win32 应用程序.

很明显,%1 代表了失败命令的第一个参数——即试图加载的可执行文件——但为什么它没有被实际路径填充?

It's clear that %1 represents the first argument to the failing command - i.e. the executable that is trying to be loaded - but why does it not get filled in with the actual path?

是调用者做错了什么,还是由于兼容性原因无法修复某些 Windows 子系统的基本故障?

Is it something that the caller is doing wrong, or is it a basic failing of some Windows subsystem that cannot be fixed for compatibility reasons?

推荐答案

错误消息来自 Windows 本身,您可以在 系统错误代码 (0-499).您使用 FormatMessage,它有一个可选的 Arguments 数组;消息中的任何 %1 都将被该数组中的第一个元素替换.如果没有为参数传递任何内容,如果使用了 FORMAT_MESSAGE_IGNORE_INSERTS 标志,则 %1 将保持不变,否则 FormatMessage 将失败't(感谢 IInspectable 提供该信息).

The error message comes from Windows itself, you can see the complete list at System Error Codes (0-499). You translate an error code returned by the API into a message using FormatMessage, which has an optional Arguments array; any %1 in the message will be replaced by the first element in this array. If nothing is passed for the arguments, the %1 will be left unchanged if the FORMAT_MESSAGE_IGNORE_INSERTS flag was used or the FormatMessage will fail if it wasn't (thanks to IInspectable for that information).

作为一个如何可能会被遗漏的示例,请考虑将错误代码立即转换为异常的代码.如果异常包含错误代码但没有其他内容,则没有上下文可以知道要传递给 FormatMessage 的内容.

As an example of how this might get missed, consider code where an error code gets converted immediately to an exception. If the exception contains the error code but nothing else, then there is no context for knowing what to pass to FormatMessage.

这篇关于为什么在“%1 不是有效的 Win32 应用程序"中很少替换 %1.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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