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 development | Windows API - Win32
Developer technologies | C++
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 49,636 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 90,686 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.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.