System Error Codes (WinError.h)
This section of the Microsoft Developer Network (MSDN) library provides detailed information about system error codes used in Windows. These codes are defined in the WinError.h header file and are returned by various Windows API functions to indicate the result of an operation.
Understanding Error Codes
When a Windows API function fails, it typically returns a value indicating the error. This value is often a numerical error code. These codes can be symbolic constants (e.g., ERROR_SUCCESS, ERROR_FILE_NOT_FOUND) or raw numerical values. The GetLastError() function is commonly used to retrieve the most recent error code set by a thread.
Common Error Code Categories
- General Errors (e.g.,
ERROR_INVALID_FUNCTION,ERROR_NOT_ENOUGH_MEMORY) - File System Errors (e.g.,
ERROR_FILE_NOT_FOUND,ERROR_PATH_NOT_FOUND) - Network Errors (e.g.,
ERROR_CONNECTION_REFUSED,ERROR_NETWORK_UNREACHABLE) - Access Denied Errors (e.g.,
ERROR_ACCESS_DENIED) - Resource Errors (e.g.,
ERROR_INVALID_HANDLE,ERROR_NO_SYSTEM_RESOURCES)
Error Code: 0x80070002 (2)
ERROR_FILE_NOT_FOUND
Description: The system cannot find the file specified.
Context: This error code is returned when an operation attempts to access a file or directory that does not exist at the specified path. This can occur during file I/O operations, launching executables, or referencing configuration files.
Common Causes:
- Incorrect file path provided to an API function.
- The file has been moved, deleted, or renamed.
- Permissions issues preventing access to the directory containing the file.
- The file is not present on the system.
Related Functions:
CreateFileFindFirstFileMoveFileCopyFile
GetLastError() to diagnose issues accurately.
Error Code: 0x80070005 (5)
ERROR_ACCESS_DENIED
Description: Access is denied.
Context: This error code indicates that the calling process does not have the necessary permissions to perform the requested operation on a resource, such as a file, registry key, or system object.
Common Causes:
- Insufficient user privileges.
- Incorrect security descriptors (ACLs) on the resource.
- Attempting to access a protected system resource.
- UAC (User Account Control) restrictions.
Related Functions:
CreateFileRegOpenKeyExOpenProcessSetFileSecurity
ERROR_ACCESS_DENIED, verify the user's or process's security context and the resource's permissions. Consider running the application with elevated privileges if appropriate and authorized.
Finding More Error Codes
You can find a comprehensive list of system error codes in the Windows SDK documentation, typically in the WinError.h header file. Many online resources and tools also provide search functionality for these codes.
For a full list of system error codes, please refer to the official Windows SDK documentation or search specific error codes.