Getting the Windows System Error Code title/description from its hex number

后端 未结 4 1349
孤城傲影
孤城傲影 2020-12-13 07:00

I\'m messing around with some windows functions using p/invoke. Occasionally, I get an error code that is not ERROR_SUCCESS (such an odd name).

Is there a way to loo

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 07:41

    You could take the defines from winerror.h at Rensselaer Polytechnic Institute, and put them into an Enum:

    public enum Win32ErrorCode : long
    {
         ERROR_SUCCESS = 0L,
         NO_ERROR = 0L,
         ERROR_INVALID_FUNCTION = 1L,
         ERROR_FILE_NOT_FOUND = 2L,
         ERROR_PATH_NOT_FOUND = 3L,
         ERROR_TOO_MANY_OPEN_FILES = 4L,
         ERROR_ACCESS_DENIED = 5L,
         etc.
    }
    

    Then if your error code is in a variable error_code you would use :

    Enum.GetName(typeof(Win32ErrorCode), error_code);
    

提交回复
热议问题