How to convert a message number to a message ID

Ahmed Osama 120 Reputation points
2023-03-02T16:43:59.56+00:00

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():

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,523 questions
C++
C++
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,636 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 43,306 Reputation points
    2023-03-02T17:48:14.8333333+00:00

    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 83,206 Reputation points
    2023-03-02T16:56:22.7366667+00:00

    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
    2023-03-03T10:04:40.3966667+00:00

    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.