Where can I find a list of all windows error codes?

淺唱寂寞╮ 提交于 2020-04-07 16:08:13

问题


In a previous question, I asked what it meant when my program returned an obscure value like

-1073741819

Well, now I'm getting another large return value,

-1073740777

And I would like to know if there is some list of all of these values and what they mean sopmewhere?


回答1:


Generally you will get better search results if you print out the error number in hex, instead of signed decimal form.

For example, your first error is -1073741819 which can also be represented by 0xC0000005 in hex. This is an "access violation" error as google will quickly tell you.




回答2:


Because the Windows error code system is extensible, there is no single place to look up all possible Windows error codes. However, you can start with:

  • Study the Structure of COM Error Codes. Sometimes knowing what facility an error comes from can help you discover what header file it comes from.
  • Visual Studio, since at least 2003, includes an ERRLOOK tool. Try that first if you're using Visual Studio.
  • Many of the codes you'll encounter are in Winerror.h. I've included a link to MSDN that contains the contents of that header file. Or you can look at the error code listing by number on this page.
  • Ideally you know what function returned the code, and then you can lookup the function on MSDN and look at all the possible return values. Of course, you'll need to refer to Winerror.h, or an another header file to get the actual values.
  • You can find (like Unix grep) in the Include directory of the platform SDK for either the hex value of the entire error code, or the decimal value of just the code section--that is, the lower 16 bits. Use HRESULT_CODE to extract that. See the Structure of COM Error Codes above.
  • There are a few error lookup tools where you can paste in a value and it looks it up in its database and tells you what it means. Look here and here.
  • Google. Use the full hex value. Sometimes you'll find very useful information, or at least clues.



回答3:


Many of them (but not I think the ones related to COM) are in a header file named winerror.h.

In (some versions of) Visual Studio, under the 'Tools' menu, you might find an menu item named 'Error Lookup...'.




回答4:


Well there's a bunch of them here,

http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspx

But when I get one like your example I just Google the number.




回答5:


NTSTATUS

NTSTATUS *covers a range of facilities
FACILITY_URT (0x013) *CLR exceptions

HRESULTS

FACILITY_NULL (0x000)
FACILITY_RPC (0x001)
FACILITY_DISPATCH (0x002)
FACILITY_RPC_STUBS (0x003)
FACILITY_USER (0x004) *multiple libraries can reuse the same error code
FACILITY_MCA_ERROR_CODE (0x005)
FACILITY_WIN32, MSDN (0x007) *standard WINAPI error codes
FACILITY_WINDOWS (0x008)
FACILITY_SECURITY (0x009)
FACILITY_CERT (0x00B)
FACILITY_INTERNET (0x00C)
FACILITY_MEDIASERVER (0x00D)
FACILITY_MSMQ (0x00E)
FACILITY_SETUPAPI (0x00F)
FACILITY_SCARD (0x010)
FACILITY_COMPLUS (0x011)
FACILITY_HTTP (0x019)
FACILITY_USERMODE_FILTER_MANAGER (0x01F)
FACILITY_WINDOWSUPDATE (0x024)
FACILITY_GRAPHICS (0x026)
FACILITY_NAP (0x027)
FACILITY_INK (0x028)
FACILITY_TPM_SOFTWARE (0x029)
FACILITY_UI (0x02A)
FACILITY_PLA (0x030)
FACILITY_FVE (0x031)
FACILITY_FWP (0x032)
FACILITY_WINRM (0x033)
FACILITY_NDIS (0x034)
FACILITY_USERMODE_HYPERVISOR (0x035)
FACILITY_USERMODE_VIRTUALIZATION (0x037)
FACILITY_USERMODE_VOLMGR (0x038)
FACILITY_BCD (0x039)
FACILITY_USERMODE_VHD (0x03A)
FACILITY_SDIAG (0x03C)
FACILITY_WEBSERVICES (0x03D)
FACILITY_WPN (0x03E)
FACILITY_MBN (0x054)
FACILITY_P2P (0x063)
FACILITY_BLUETOOTH_ATT (0x065)
FACILITY_AUDIO (0x066)
FACILITY_IMAPI2 (0x0AA)
FACILITY_RTC_INTERFACE (0x0EE)
FACILITY_SIP_STATUS_CODE (0x0EF)
FACILITY_PINT_STATUS_CODE (0x0F0)
FACILITY_MAX_WDSTPTMGMT (0x110)
FACILITY_WDSMCSERVER (0x121)
FACILITY_MAX_WDSMC (0x122)
FACILITY_MAX_WDSCP (0x125)
FACILITY_BACKUP (0x7FF)
FACILITY_NTDSB (0x800)
FACILITY_DIRECT3D10 (0x879)
FACILITY_DXGI (0x87A)
FACILITY_DXGI_DDI (0x87B)
FACILITY_DIRECT3D11 (0x87C)
FACILITY_DWRITE (0x898)
FACILITY_D2D (0x899)
FACILITY_DEFRAG (0x900)
FACILITY_ONLINE_ID (0xA02)

Bug Checks

Bug Check Code Reference *aka Blue Screens




回答6:


Here is a 100% free online tool "MagnumDB" for "Magical Number Database" that contains about 350,000 constants (integers, strings, guids, etc.) parsed from the whole Windows SDK files (~6,000 files), that you can query by value and by name. Disclaimer: I wrote it after years of searching for constants, names, guids...

Here is the result for -1073741819 which maps to 3 different constants (with the same value and the same meaning) defined in 3 different files, the most common being STATUS_ACCESS_VIOLATION.

And for -1073740777 which is STATUS_INVALID_CRUNTIME_PARAMETER defined in winnt.h.

It supports integers, signed integers, unsigned integers, hexadecimal notation, and also raw text searches. It also knows the value of constants that are defined by operations (like c2 = c1 + 1).




回答7:


Here's a class in C# to help you convert the error codes to string:

public static class WinErrors
{
    #region definitions
    [DllImport("kernel32.dll", SetLastError = true)]
    static extern IntPtr LocalFree(IntPtr hMem);

    [DllImport("kernel32.dll", SetLastError = true)]
    static extern int FormatMessage(FormatMessageFlags dwFlags, IntPtr lpSource, uint dwMessageId, uint dwLanguageId, ref IntPtr lpBuffer, uint nSize, IntPtr Arguments);

    [Flags]
    private enum FormatMessageFlags : uint
    {
        FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100,
        FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200,
        FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000,
        FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000,
        FORMAT_MESSAGE_FROM_HMODULE = 0x00000800,
        FORMAT_MESSAGE_FROM_STRING = 0x00000400,
    }
    #endregion

    /// <summary>
    /// Gets a user friendly string message for a system error code
    /// </summary>
    /// <param name="errorCode">System error code</param>
    /// <returns>Error string</returns>
    public static string GetSystemMessage(int errorCode)
    {
        try
        {
            IntPtr lpMsgBuf = IntPtr.Zero;

            int dwChars = FormatMessage(
                FormatMessageFlags.FORMAT_MESSAGE_ALLOCATE_BUFFER | FormatMessageFlags.FORMAT_MESSAGE_FROM_SYSTEM | FormatMessageFlags.FORMAT_MESSAGE_IGNORE_INSERTS,
                IntPtr.Zero,
                (uint) errorCode,
                0, // Default language
                ref lpMsgBuf,
                0,
                IntPtr.Zero);
            if (dwChars == 0)
            {
                // Handle the error.
                int le = Marshal.GetLastWin32Error();
                return "Unable to get error code string from System - Error " + le.ToString();
            }

            string sRet = Marshal.PtrToStringAnsi(lpMsgBuf);

            // Free the buffer.
            lpMsgBuf = LocalFree(lpMsgBuf);
            return sRet;
        }
        catch (Exception e)
        {
            return "Unable to get error code string from System -> " + e.ToString();
        }
    }
}


来源:https://stackoverflow.com/questions/1081276/where-can-i-find-a-list-of-all-windows-error-codes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!