How do I deal with placeholders for Win32 error messages?

David Heffernan

I would like to present meaningful error messages when my program encounters Win32 errors. I call GetLastError, and then FormatMessage. But some of the error messages contain placeholders. For instance, ERROR_BAD_EXE_FORMAT has the text:

%1 is not a valid Win32 application.

Presumably, the %1 is meant to be replaced by the name of the module which is not valid. How can I effect that replacement?

Note that I would ideally like a general solution because I note that there are many errors with placeholders. I can see the following messages in the documentation:

  • The wrong diskette is in the drive. Insert %2 (Volume Serial Number: %3) into drive %1.
  • The operating system cannot run %1.
  • This version of %1 is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.
  • The image file %1 is signed, unable to modify.
  • The system cannot find message text for message number 0x%1 in the message file for %2.
  • ... and so on.
David Heffernan

I think Raymond Chen effectively answers the question in a comment on his blog where he writes:

It bugs me too that system error messages contain %1 insertions that you just have to "know" on a case-by-case basis.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I deal with these error messages in Processing using the UnfoldingMaps library

From Dev

I there a microsoft resource for translated Windows Winapi/Win32/system error messages?

From Dev

How can I convert Win32 mouse messages to WPF mouse events?

From Dev

how can i solve this error in my win32 reading image file code

From Dev

How do I get a string resource by name in win32 or MFC?

From Dev

How do I manipulate the icon for an existing desktop shortcut using Win32?

From Dev

How do I find position of a Win32 control/window relative to its parent window?

From Dev

How do I properly render OpenGL inside of a Win32(C++) static control?

From Dev

How do I clear a win32 cmd console window without using system() in C?

From Dev

How do I call the Win32 API version of a function from an MFC application?

From Dev

How do I add an icon to the taskbar for a simple win32 dialog?

From Dev

How do I call win32 dll from powerbuilder11.5?

From Dev

How do I open a program in a Win32 Console without cmd.exe?

From Dev

How do I `std::bind` a non-static class member to a Win32 callback function `WNDPROC`?

From Dev

How do I clear a win32 cmd console window without using system() in C?

From Dev

How do I call the Win32 API version of a function from an MFC application?

From Dev

How do I get a string resource by name in win32 or MFC?

From Dev

How do I properly render OpenGL inside of a Win32(C++) static control?

From Dev

How do I suppress error messages on file.delete?

From Dev

How do I catch exceptions that have specific error messages in Python?

From Dev

How do I combine resource strings for validation attribute error messages?

From Dev

How do I copy error messages in Visual Studio

From Dev

How do I see error messages generated in PowerShell event handlers?

From Dev

How do I interpret PostgreSQL error messages from within Go?

From Dev

Rails 5 throw abort : how do I setup error messages?

From Dev

How do I test Moose subtype error messages?

From Dev

How do I suppress console/cmd error messages in python

From Dev

How do I display the error messages in signup form?

From Dev

How do I ignore warnings, but keep error messages from 'find'

Related Related

  1. 1

    How do I deal with these error messages in Processing using the UnfoldingMaps library

  2. 2

    I there a microsoft resource for translated Windows Winapi/Win32/system error messages?

  3. 3

    How can I convert Win32 mouse messages to WPF mouse events?

  4. 4

    how can i solve this error in my win32 reading image file code

  5. 5

    How do I get a string resource by name in win32 or MFC?

  6. 6

    How do I manipulate the icon for an existing desktop shortcut using Win32?

  7. 7

    How do I find position of a Win32 control/window relative to its parent window?

  8. 8

    How do I properly render OpenGL inside of a Win32(C++) static control?

  9. 9

    How do I clear a win32 cmd console window without using system() in C?

  10. 10

    How do I call the Win32 API version of a function from an MFC application?

  11. 11

    How do I add an icon to the taskbar for a simple win32 dialog?

  12. 12

    How do I call win32 dll from powerbuilder11.5?

  13. 13

    How do I open a program in a Win32 Console without cmd.exe?

  14. 14

    How do I `std::bind` a non-static class member to a Win32 callback function `WNDPROC`?

  15. 15

    How do I clear a win32 cmd console window without using system() in C?

  16. 16

    How do I call the Win32 API version of a function from an MFC application?

  17. 17

    How do I get a string resource by name in win32 or MFC?

  18. 18

    How do I properly render OpenGL inside of a Win32(C++) static control?

  19. 19

    How do I suppress error messages on file.delete?

  20. 20

    How do I catch exceptions that have specific error messages in Python?

  21. 21

    How do I combine resource strings for validation attribute error messages?

  22. 22

    How do I copy error messages in Visual Studio

  23. 23

    How do I see error messages generated in PowerShell event handlers?

  24. 24

    How do I interpret PostgreSQL error messages from within Go?

  25. 25

    Rails 5 throw abort : how do I setup error messages?

  26. 26

    How do I test Moose subtype error messages?

  27. 27

    How do I suppress console/cmd error messages in python

  28. 28

    How do I display the error messages in signup form?

  29. 29

    How do I ignore warnings, but keep error messages from 'find'

HotTag

Archive