Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is %1 rarely substituted in "%1 is not a valid Win32 application."

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 is not a valid Win32 application.

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?

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?

like image 804
OrangeDog Avatar asked Apr 25 '17 15:04

OrangeDog


People also ask

What is 1 is not a valid Win32 application?

This message, not a valid Win32 application, may be perplexing, but it simply indicates that the version of the Window you are using is not supported to run this app because your version of Windows cannot comprehend the contents of the file.

Is not valid Win 32 application?

The message "winzipxxx.exe is not a valid win32 application" indicates that the EXE file did not download completely. When Windows then tries to run what appears to be an executable file, it finds that it is not a valid Windows 32-bit application file due to the incomplete download.

How do I fix Error 193 1 is not a valid Win32 application?

Resolving The Problem This issue can occur if a file or folder with name 'Program' exists on the same drive where the Cognos products are installed.To resolve this, either rename the file/folder or delete it.


2 Answers

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).

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.

like image 60
Mark Ransom Avatar answered Oct 16 '22 10:10

Mark Ransom


The caller is doing everything right. They are calling FormatMessage, passing along the FORMAT_MESSAGE_IGNORE_INSERTS flag1), like everyone should. The caller is not in control of the message that gets created, and has no way of knowing, that it should pass additional arguments, what types they should be or how many.

This was an early design bug in the Windows error reporting system, and you'll see those placeholders in every well-behaved application.


1)See The importance of the FORMAT_MESSAGE_IGNORE_INSERTS flag.
like image 33
IInspectable Avatar answered Oct 16 '22 08:10

IInspectable