How to convert a message number to a message ID

Ahmed Osama 120 Reputation points

How to convert a message (ex:13928) to an Message ID (ex: ERROR_IPSEC_DOSP_STATE_LOOKUP_FAILED) How to do that?

When retrieving an error code using GetLastError():


It retrives an code, not a message ID or message

How do I convert an error code to a message ID and without loops?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 40,286 Reputation points

    Since winerror.h uses the preprocessor #define to associate a "message id" with the numeric value you would need to create your own lookup table. There is no Windows API function to convert the actual error code to the "message id" that is seen by the preprocessor.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Castorix31 81,636 Reputation points

    With FormatMessage

    But it depends on the resource DLL

    13928 gives "La protection DoS IPsec n’a pas pu rechercher l’état.\r\n" on my french OS

    1 person found this answer helpful.

  2. simonberrurier-7045 41 Reputation points

    It retrives an code, not a message ID or message

    FormatMessage is the way to get the message from a system code

    1 person found this answer helpful.